我有4个测试分布在3个测试类中。如果我一个一个地运行每个测试,它们都可以成功。但是同时运行(并行?)时,除了第一个触发的测试外,所有测试都失败了。
我的测试需要相同的设置,因此我有一个所有测试都使用的框架:
public class CompositionRootFixture
{
public Container Container { get; private set; } // Simple Injector Container
public CompositionRootFixture()
{
Container = new Container();
/* code removed for clearity */
Container.Verify();
}
}
并且可以像下面这样在我的测试类中使用:
public class CommandProcessorTests : IClassFixture<CompositionRootFixture>
{
private readonly CompositionRootFixture _fixture;
public CommandProcessorTests(CompositionRootFixture fixture)
{
_fixture = fixture;
}
[Fact]
public async Task TestExecutingUsingContainerForResolution()
{
var commands = _fixture.Container.GetInstance<IExecuteCommands>();
var command = new FakeCommandWithoutValidator();
await commands.Execute(command);
Assert.Equal("faked", command.ReturnValue);
}
}
我很难理解如何使用 IClassFixture<T>
,而且文档在设置方面并没有提供太多帮助。我正在使用最新的 XUnit 2.0.0-beta5-build2785 版本。
失败描述:
---- System.InvalidOperationException : The configuration is invalid. Creating the instance for type IHandleCommand<FakeCommandWithoutValidator> failed. The registered delegate for type IHandleCommand<FakeCommandWithoutValidator> threw an exception. The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
-------- SimpleInjector.ActivationException : The registered delegate for type IHandleCommand<FakeCommandWithoutValidator> threw an exception. The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
------------ SimpleInjector.ActivationException : The configuration is invalid. The type HandleFakeCommandWithoutValidator is directly or indirectly depending on itself.
---- The following constructor parameters did not have matching fixture data: CompositionRootFixture fixture