The basic method for unit testing is to call the testedCodeFunction, enter the parameter value of the function, obtain the returned results, and then compare them with the expected test results. If they are equal, the test is passed. Otherwise, the test fails.
1. Use of assert class
Assert. Inconclusive () indicates an unverified test;
Assert. areequal () test whether the specified value is equal. If the value is equal, the test passes;
Aresame () is used to verify that the specified two object variables point to the same object. Otherwise, it is considered as an error.
Arenotsame () is used to verify that the specified two object variables point to different objects. Otherwise, it is considered as an error.
Assert. istrue () test whether the specified condition is true. If it is true, the test passes;
Assert. isfalse () test whether the specified condition is false. If it is false, the test passes;
Assert. isnull () test whether the specified object is a null reference. If it is null, the test passes;
Assert. isnotnull () test whether the specified object is not empty. If not, the test passes;
2. Use of the collectionassert class
Used to verify whether the object set meets the conditions
Use of the stringassert class
Used to compare strings.
Stringassert. Contains
Stringassert. Matches
Stringassert.tar twith.
Test the MVC