nunit如何使用一次性设置方法(适用于所有测试)[重复]

时间:2023-01-16 15:41:16

This question already has an answer here:

这个问题在这里已有答案:

I need a once-off setup method, called only once, across all test fixtures.

我需要一个一次性设置方法,在所有测试夹具上只调用一次。

This is to setup common stuff like AutoMapper, some mocks used by everything.

这是设置常见的东西,如AutoMapper,一些模拟使用的所有东西。

How can I do this? (And I'm not talking about TestFixtureSetup)

我怎样才能做到这一点? (我不是在谈论TestFixtureSetup)

1 个解决方案

#1


1  

You could have all your test classes inherit from a base test class, and do your setup in the constructor.

您可以让所有测试类继承自基础测试类,并在构造函数中进行设置。

public class TestBase {
     public TestBase() {
       // Global setup
     }
}

public class MyTest : TestBase {
     // Tests
}

#1


1  

You could have all your test classes inherit from a base test class, and do your setup in the constructor.

您可以让所有测试类继承自基础测试类,并在构造函数中进行设置。

public class TestBase {
     public TestBase() {
       // Global setup
     }
}

public class MyTest : TestBase {
     // Tests
}