重用具有多个实现的测试套件?
我正在使用 nUnit 进行测试。我有一套针对我的 IFoo 界面运行的测试;测试夹具设置确定要加载和测试哪个 IFoo 实现。
我试图弄清楚如何针对 IFoo 实现列表运行相同的套件,但没有看到任何方法可以在不手动修改设置的情况下测试所有实现。
有人解决过这个问题吗?
I'm testing with nUnit. I have a suite of tests that run against my IFoo interface; the Test Fixture Setup determines which IFoo implementation to load and test.
I'm trying to figure out how to run the same suite against a list of IFoo implementaions, but don't see any way to test all implementations without manually modifying the Setup.
Has anyone tackled this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个基测试类,其中包含 IFoo 实现之间共享的测试,如下所示:
现在为要测试的每个实现创建一个非常小的派生类:
编辑:显然 NUnit 还支持 参数化测试装置,甚至支持具有参数类型的通用测试装置。链接文档中的示例:
此示例有点简单,因为它具有类型的
new()
约束。但您也可以使用Activator.CreateInstance
并从TestFixture
属性传递IFoo
实现的构造函数参数。Create a base test class that contains tests shared between IFoo implementations like this:
Now create a very small derived class for each implementation you want to test:
edit: Apparently NUnit also has support for parameterized test fixtures, even generic test fixtures with parameter types are supported. Example from the linked documentation:
This example is a bit simplistic because it has the
new()
constraint for the types. But you could also useActivator.CreateInstance
and pass the constructor arguments for yourIFoo
implementations from theTestFixture
attributes.实现此目的的几种方法之一:
One of several ways to accomplish this: