繁体   English   中英

在单个测试类中测试接口的多个实现

[英]Testing multiple implementations of an interface in a single test class

我需要在类级别传递测试数据,但是TheoryInlineData属性只能用于方法。

public class ContainerTests : TestFixture
{
    private IContainer _container;

    public ContainerTests(string containerName)
    {
        _container = CreateContainer(containerName);
    }

    [Fact]
    public void ResolveJobFactory()
    {
        IJobFactory jobFactory = _container.Resolve<IJobFactory>();
    }

    private IContainer CreateContainer(string containerName)
    {
        if (containerName == "CastleWindsor")
        {
            return new WindsorContainerAdapter();
        }
        //other adapters

        throw new NotImplementedException();
    }
}

有没有办法在xUnit.net中实现类似的东西?

在单个测试类中测试接口的多个实现

别! 每个实现都有一个测试类。

编辑:根据评论,我建议有一个带有所有常见测试的基础TestClass,然后是一个继承自这个基类的每个实现的测试类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM