Developer perspective: Using vsts for Application Analysis and unit testing (II)

Source: Internet
Author: User
Unit Test

Unit Testing is especially important for developers. If developers accept TDD, unit testing will become an indispensable part, although the size of the unit to be tested (The unit here includes types, methods, etc.) varies, the vsts test tool generates a unit test specifically for methods (including private methods.

Unit Tests are executed by directly calling a class method (passing corresponding parameters ).OthersSource code. Therefore, if the assert statements are included, they can test the actually generated value based on the expected value. The unit test method is located in the test class and the test class is stored in the source code file.

You can use the code generation function of the initial source code that can be used to create a test to create a unit test, or you can write a test completely manually. Regardless of the method used, the test class and all test methods are identified by programming attributes. For example, if you use the [testclass ()] feature to mark each test class, each unit test is a test method marked with the [testmethod ()] feature. These attributes are automatically assigned when a unit test is generated. If you manually write the unit test code, you must add the attributes of the class and method.

In terms of the file organization structure, we are used to passing the "Project name" +"Test"Character representation, and for each test class, they are used to adding the suffix fixture, which is alsoMicrosoftRecommended method.

The following is a piece of test code from the Unity project in the Microsoft mode and practice team:

[Testmethod]
Publicvoidresolverwithelementsreturnsemptyarrayiftherearenoelements ()
{
Iunitycontainer Container = newunitycontainer ();
Objecto1 = newobject ();
Objecto2 = newobject ();
Objecto3 = newobject ();

Container
. Registerinstance <Object> ("O1", O1)
. Registerinstance <Object> ("O2", O2 );

Buildercontext context = getcontext (container, typeof (object ));

Resolvedarraywithelementsresolverpolicy Resolver
= Newresolvedarraywithelementsresolverpolicy (typeof (object ));

Object [] Results = (object []) resolver. Resolve (context );

Assert. isnotnull (results );
Assert. areequal (0, results. Length );
}

All test operations in the vsts can be completed by running the command in the "test" menu, as shown in Figure 8:

Figure 8

You can create a new test, run the test here, or run the unit test for the entire solution.

Team collaboration

Vsts not only brings powerful code measurement, analysis, unit testing, and other functions to developers, but also reflects the concept of team collaboration, now we can install the team resource manager directly on the vsts (in the next vsts version, the team resource manager does not need to be installed separately), and the team resource manager is the team Foundation client, you can access the functions contained in the team Foundation Server:

· Work item

· Team Project

· Team documents

· Report

· Team Generation

· Source code management

After the team resource manager is installed, you can directly connect to the team Foundation server to manage the resources, as shown in Figure 9:

Figure 9 Summary

From the developer's perspective, Visual Studio team system not only brings powerful code measurement, code analysis, unit testing, and other functions to developers, but also shows perfect team collaboration, the team resource manager is a good embodiment, greatly improving the efficiency of team collaboration.

 

From: http://www.51testing.com/

 

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.