0) Create class, Write method class
1) In the method right-click, there will be a < create unit test > option between the Run test (T) and the Debug Test (D). There is a 2, no then 1.0
1.0) Menu bar Tools--Customize--context menu--Editor Context menu | Code Window--Inside Find Create Unit Test (C) and pull to run test and debug test
1.1) Turn off restart VS, add new project, test---unit test project. This will allow the original gray option to be selected if the brush is done.
2) Check the method that needs to be tested, name, will automatically create a new unit test project, in Programtest write the required test code.
---------------------------------------------------------------------------------------
Test method:
1, the use of the Assert class
Assert.Inconclusive () indicates a test that is not validated;
Assert.AreEqual () tests whether the specified values are equal, and if so, the test passes;
Aresame () is used to verify that the specified two object variables are pointing to the same object, otherwise it is considered an error
Arenotsame () is used to verify that the specified two object variables are pointing to different objects, otherwise it is considered an error
Assert.istrue () tests if the specified condition is true, and if true, the test passes;
Assert.isfalse () tests whether the specified condition is false and if false, the test passes;
Assert.isnull () tests whether the specified object is a null reference, and if it is empty, the test passes;
Assert.isnotnull () tests whether the specified object is non-null, and if not NULL, the test passes;
2, the use of Collectionassert class
Used to verify whether the collection of objects satisfies the criteria
Use of the Stringassert class
Used to compare strings.
Stringassert.contains
Stringassert.matches
Stringassert.tartwith
Visual Studio comes with unit test demo