Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 是否存在MSTest'的非静态等价物;s[ClassCleanup]&;[分类初始化]?_Unit Testing_Integration Testing_Mstest_System Testing - Fatal编程技术网

Unit testing 是否存在MSTest'的非静态等价物;s[ClassCleanup]&;[分类初始化]?

Unit testing 是否存在MSTest'的非静态等价物;s[ClassCleanup]&;[分类初始化]?,unit-testing,integration-testing,mstest,system-testing,Unit Testing,Integration Testing,Mstest,System Testing,MSTest的[ClassCleanup]和[ClassInitialize]是否有非静态等价物 我正在使用MSTest进行一些系统/集成级测试,我不想担心在测试中清理和初始化连接 示例代码: [TestClass] public class DefectCreatorTest { private long _cookie; private soapcgi _soap; [ClassInitialize] public void Initialize()

MSTest的[ClassCleanup]和[ClassInitialize]是否有非静态等价物

我正在使用MSTest进行一些系统/集成级测试,我不想担心在测试中清理和初始化连接

示例代码:

[TestClass]
public class DefectCreatorTest
{
    private long _cookie;
    private soapcgi _soap;

    [ClassInitialize]
    public void Initialize()
    {
        _soap = new soapcgi {Url = "http://localhost:80/scripts/soapcgi.exe"};
        _cookie = Transaction.Login(_soap);
    }

    [ClassCleanup]
    public void TearDown()
    {
        Transaction.Logout(_cookie, _soap);
    }

    [TestMethod]
    public void CreateDefectTest()
    {
        var result = _soap.Foo();
        Assert.AreEqual("bar", result);
    }
}

回答你的问题,据我所知-不,MSTest中没有非静态的等价物

但是:

  • 查看您的代码,没有理由不将
    \u cookie
    \u soap
    初始化
    拆卸
    一起设置为静态。这样做会让您在编写测试时忘记配置问题
  • 如果您愿意“跳转”,则可以将与的NUnit等价物应用于静态和实例方法

  • 你说的非静态是什么意思?示例代码有什么问题?示例代码已编译,但不会运行。用ClassInitialize修饰的方法必须是静态方法。测试不会运行,因为Initialize方法需要将TestContext传递到安装方法中,即使没有使用它。