Unit vs units Test

Source: Internet
Author: User

VS Unit Testing (unit)

I. What is unit testing and its role?

when you write a small amount of code, you can often create a new console project (console application), create a new Web site project (Web Form), and then test the code in it. Once the amount of code and the logical relationship becomes complex,

This test will be difficult to expand and not be maintainable. And a lot of functional code, not completely out of the project to achieve. For example, in a Web project there is a class library, wrote some methods of the model layer, in order to

To verify the correctness of the method, to test the method, you may have to refer to a large number of models, interfaces, and library functions in the project. Wait until the compilation can pass, but find that you must log in to call the method or your directory

(Directory) has no access at all, so it has to modify the authorization configuration or add login methods. So one layer down, your test involves almost every corner of the project, and the test plan does not have

Reuse of the standby height.

Let's take VS2012 as an example to see how to Do unit testing in Visual Studio.

Two. Use of vs2012 unit?

1. Right-add-new item on your project solution:

2. Installed-visual c#-Test-Unit test project, then name the webos.mrs.unittest[project name yourself, make sense on the line]:

3. At this point, you will see there is a class under the project, you rename the class name, such as the class name I tested, such as:

The difference between a test class and a normal class is that the added property is: "TestClass"

The difference between a test function and a normal function is that the added property is: "TestMethod"

4. The test class has a very important class that is: Assert (assert):

For example, the following test is a paginated return list:

Use Assert.isnotnull (list), meaning that I assert that the list object is not empty, and if it is empty, the test passes without being empty. 】

5. Run or debug:

Unit vs units 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.