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