Simple Example of unit test in MVC

Source: Internet
Author: User

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

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.