When using [classinitialize] in unit testing, this method must be a static public method. If no value is returned, an error should be reported using a testcontext parameter.

Source: Internet
Author: User

 

Using Microsoft. visualstudio. testtools. unittesting;

If the DLL is

C: \ Program Files \ Microsoft Visual Studio 9.0 \ common7 \ ide \ publicassemblies \ Microsoft. visualstudio. qualitytools. unittestframework. dll

If the version is 9.0.0.0, [classinitialize] indicates that this method must be a static public method. If no value is returned and a testcontext parameter is used, an error is returned! I don't know if it is a Microsoft Bug.

 

Solution:

Change the DLL to c: \ Program Files \ Microsoft Visual Studio 11.0 \ common7 \ ide \ referenceassemblies \ V2.0 \ Microsoft. visualstudio. qualitytools. unittestframework. dll.

Version: 10.1.0.0

[Classinitialize]
Public static void myclassinitialize (testcontext context)
{
Sysconfig. loadcfg ();
}

 

Share a standard Ms Unit Test method:

# Region additional test features // You can also use the following features when writing a test: // use classinitialize to run the code before the first test in the running class [classinitialize ()] public static void myclassinitialize (testcontext) {} run the Code [classcleanup ()] public static void myclasscleanup () {} Use testinitialize to run the Code [testinitialize ()] public void mytestinitialize () {} before running each test. Use testcleanup to run the Code [testcleanup ()] After running each test. public void mytestcleanup () {}# endregion

  

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.