NUnit:跨多个夹具的测试夹具中的每个测试的设置和拆卸 [英] NUnit: SetUp and TearDown for each test in a test fixture across multiple Fixtures

查看:60
本文介绍了NUnit:跨多个夹具的测试夹具中的每个测试的设置和拆卸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个通用的 SetUp 和 TearDown,它可以在跨多个设备的每个测试中运行,但都在一个公共命名空间内.这将类似于 [SetUpFixture] 属性,但会在每次测试时运行.

I would like to have a generic SetUp and TearDown that is run with every test across multiple fixtures but all within a common namespace. This would be something similar to the [SetUpFixture] attribute but would be run with every test.

我尝试将基类与 [SetUp] 一起使用,但 resharper 将其解析为不确定的,这并不理想.

I've tried using a base class with [SetUp] but resharper resolves this as inconclusive which isn't really ideal.

推荐答案

我认为将基类与通用代码一起使用没有任何问题.

I don't see any problem in using a base class with the generic code.

public class BaseTest 
{
    [SetUp] 
    public void SetUp()
    { 
        //Do generic Stuff 
    }

    [TearDown] 
    public void TearDown()
    {
        // Do generic stuff 
    }



[TestFixture]
public class TestClass : BaseTest
{
    [SetUp] 
    public void SetUp()
    { 
        //Do Stuff 
    }

    [TearDown] 
    public void TearDown()
    {
        // Do stuff 
    }

这篇关于NUnit:跨多个夹具的测试夹具中的每个测试的设置和拆卸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆