我应该使用AutoFixture来测试我的洋葱的核心元素,它没有依赖性吗?

这个问题来自我之前的问题: 如何使用OneTimeSetup? 特别是回答者之一的回答。 请参阅以下代码:

[TestFixture] public class MyFixture { IProduct Product; [OneTimeSetUp] public void OneTimeSetUp() { IFixture fixture = new Fixture().Customize(new AutoMoqCustomization()); Product = fixture.Create(); } //tests to follow } 

AutoMoq仅用于创建模拟吗? 我问的原因是因为我之前正在阅读一个问题,其中回答者暗示它也用于创建普通类型,即不是模拟。

我想测试我的Onion的Core元素,它没有依赖关系。 因此我应该使用AutoFixture吗?

AutoMoq Glue Library为AutoFixture提供了Auto-Mocking Container的附加function; 也就是说,它不仅可以为您组成普通对象 – 它还可以为您的对象提供模拟对象,如果它们是如此需要的话。

AutoFixture本身不是自动模拟容器,而是自动化四阶段测试模式的Fixture Setup阶段的库,如xUnit测试模式中所述 。 它还使您能够自动化与Test Data Builder模式关联的代码。

它明确地被设计为隐式设置的替代品,所以我认为将它与设置方法和可变类字段一起使用是没有意义的,正如这个问题所暗示的那样。 换句话说,AutoFixture的全部意义在于它使您能够编写如下的独立unit testing:

 [TestFixture] public class MyFixture { [Test] public void MyTest() { var fixture = new Fixture().Customize(new AutoMoqCustomization()); var product = fixture.Create(); // Use product, and whatever else fixture creates, in the test } } 

即使它们没有依赖关系,你也绝对可以用它来测试你的单元,但在这种情况下,你可能不需要AutoMoq Customization。