Visual Studio comes with unit test demo

Source: Internet
Author: User


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

Related Article

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.