我已经开始尝试使用 AutoFixture。在我的研究中,我发现有InlineAutoDataAttribute
一个可以用来生成具有不同输入参数的多个测试用例(给定一些要求)。但是,InlineAttribute
同样InlineAutoDataAttribute
只能处理编译const
数据。所以我去寻找类似的东西MemberAutoDataAttribute
,因为它MemberDataAttribute
可以让我输入一个非“编译时常量”对象的集合,比如一个Exception
实例的集合。可悲的是,这个属性不存在。
有什么方法可以重用使用 AutoFixture 的测试,以便它可以生成多个测试用例?这可以通过一些ICustomization
实现来实现吗?
下面是我描述的情况的一个例子。请注意,这MyCustomAutoDataAttribute
只是AutoDataAttribute
导致AutoMoqCustomization
为夹具配置的基本继承对象。
[Theory, MyCustomAutoDataAttribute]
public void FooBar(Exception exception, [Frozen] ISomeInterface)
{
...
ISomeInterface.Setup(i => i.SomeMethod()).Throws(exception);
...
}