VS2013 Unit Test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.