Three initialize and cleanup methods of Visual Studio

Source: Internet
Author: User
Tags sorted by name

There are three initialize and cleanup methods in the visual stuido Metadata module. During the development, initialization can be performed before the testmethod execution line, and some cleanup operations can be performed after the end, the three initialize and cleanup operators have different time periods, such as: I guess few knowAssemblyOfInitializeAndCleanupCall initialize in front of all testmethod commands in the same example, and call cleanup after all testmethods in the same example.

 

Assemblyinitialize and assemblycleanup

Call initialize in front of all testmethod commands in a trial case and cleanup in the end of all testmethods in a trial case, in a typical case, only one assemblyinitialize and assemblycleanup can be performed once. This usually applies to the entire scenario, for example: the operation and detachment of the resource.

 
// The class of assemblyinitialize and assemblycleanup must have testclass, instead, it is not static. The parameter [testclass] public/* Static */class testhelper {// method name can be used as the parameter, but it must be static, and there is a metric data context [assemblyinitialize] public static void assemblyinitialize (testcontext context) {// The most initialization of a typical case} // The method name can be used immediately, however, it must be static [assemblycleanup] public static void assemblycleanup () {// end of a typical case }}

Note:

If there are two legal cases

Testprojecta has

---- Assemblyinitializea

---- Assemblycleanupa

---- Test1

---- Test3

Testprojectb has

---- Assemblyinitializeb

---- Assemblycleanupb

----Test2

 

Because the sequence of sequence values of two rows can be sorted by name sequence, the sequence of the called sequence rows is as follows: test1, Test2, and test3.

----Assemblyinitializea

---- Test1

----Assemblyinitializeb

---- Test2

---- Test3

---- Assemblycleanupa

---- Assemblycleanupb

If there are multiple concurrent upload cases at the same time, note that the rows may be crossed.Initialize.

Classinitialize and classcleanup

All testmethod requests are called before and after the same testclass. Each testclass can have only one classinitialize and classcleanup, and each testclass calls only once, it is already in the textbook of Visual Studio in the single-dollar linear regression example. You only need to remove the linear solution.

[Testclass] public class programtest {.......... // call before test1 and Test2, the method name can be called immediately, but it must be static, and there must be a dynamic value of context [classinitialize] public static void classinitialize (testcontext) {..........} // call after test1 and Test2, and the method name can be called immediately, but it must be static [classcleanup] public static void classcleanup () {..........}.......... [testmethod] public void test1 (){..........} [testmethod] public void Test2 (){..........}}

Note:

There are also crossover rowsInitializeProblem.

Testinitialize and testcleanup

In a testmethod under a testclass, each call is performed before and after the production line, and each testclass can have only one testinitialize and testcleanup, each testmethod is called only once, it is already in the textbook of Visual Studio in the single-dollar authentication solution case. You only need to remove the solution and use it to initialize and clear each testmethod.

[Testclass] public class programtest {.......... // call before test1 or Test2, and the method name can be called immediately, but it must be static [testinitialize] public static void testinitialize () {..........} // call after test1 or Test2, and the method name can be called immediately, but it must be static [classcleanup] public static void testcleanup () {..........}.......... [testmethod] public void test1 (){..........} [testmethod] public void Test2 (){..........}}

 

Additional information
    • [Msdn] Architecture
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.