Installing Unit Test Generator
1. Open VS2013, select Tools-Extensions and updates, search for and install unit Test Generator.
2. Right-click on the class method, select Generate unit test, and directly select OK after the popup, the test project of vs2013 unit test will be generated automatically.
One-Step debugging method:
1. Unit Test Code Set breakpoints
2. Right-click Debug Test
To assert the use of an Assert class:
The Microsoft.VisualStudio.TestTools.UnitTesting namespace provides several types of assert classes, which assert that in a test method, you can call any number of Assert class methods, such as Assert.AreEqual () method. There are many ways to choose an Assert class, many of which have multiple overloads.
Use the Collectionassert class to compare the collection of objects, or to validate the state of one or more collections.
You can use the Stringassert class to compare strings.
Example:
System.IO.FileInfo file = null; System.IO.FileInfo file1 = file; System.IO.DirectoryInfo dir = null; String temptrue = "T"; String tempfalse = "F"; Assert.AreEqual (Temptrue, Tempfalse); Two objects are not the same, test failed Assert.arenotsame (File1, temptrue); Two imported objects are the same, test failed " Assert.aresame (file1, file); Two of the objects introduced are not the same Assert.fail (); Whatever it is, just announce the test failure. Assert.Inconclusive (); Same as fail, but not fail, only test cannot pass Assert.isfalse (TRUE); If it is true, indicates that the test failed Assert.istrue (FALSE); If False, ask the test to fail Assert.isinstanceoftype (True,temptrue.gettype ()); Type is different, test fails Assert.isnull (Tempfalse); Not empty so the test failed |
VS2013 Unit Test