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