VS2012 Creating unit Tests

Source: Internet
Author: User

Many people have a wrong understanding of unit tests. Think that unit testing is too time-consuming and affects progress. Actually do the project only to find that the code does not take a long time, but the bug is time-consuming. If we have a unit test, it will save us the development time from the first Test in place. There is a deeper meaning to unit testing. 1 It is a design 2 is a tool for project progress monitoring. 3 is also the best tool for learning open source projects.


Of course there are many tools for unit testing, so let's take a look at the unit test steps of VS2012.

The first step: Configure the environment for the test.

VS2010 can skip this step directly. Right-click on a class or method to see it directly. But the VS2012 need to be tuned out.

This step is a lot of online tutorials. Link is an article in the blog Park. Http://www.cnblogs.com/Gyoung/p/3143438.html


Step Two: Create a test project

Right-click the solution-add-new project-Test---test project.


Step three: Create a test class

The third step has two options.

First Kind

① Right-click the test Project-add unit tests. TestClass and TestMethod are the equivalent of tags in automatically created code.

② Add a reference. Add the required references to the previous layer.

For example, if you use layer three, you want to test the class and method of the D layer, then you should add all the references to the B layer.

③ write the contents of the test class. Take a simple example of what is called an assertion that involves a comparison of hypothetical values and results.

The above method is suitable for high-level people to write. But there is nothing really clear about the merits.


The second Kind

① find the class you want to test. Right--Create unit test--all the way.

The ② system will give an assertion that you can also fill out yourself. After all, many companies are testing the code coverage by certain requirements.


Fourth step: Verify your test.

Right-click on your test class and run the test. Wait a moment and the test results will appear.







VS2012 Creating unit Tests

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.