Closed dmitry-kosar closed 3 years ago
Hi @dmitry-kosar
I think you don't have to call InitializeAsync()
from your constructor. It is executed by the xunit framework once per run.
Hello @dmitry-kosar Is the CI pipeline running the same arch as you do locally?
Hello @dmitry-kosar Is the CI pipeline running the same arch as you do locally?
Hello, @dgvives
I'm running tests locally on MBP Intel Core i5 macOs Catalina.
And CI runs on ubuntu-latest
Hi @dmitry-kosar I think you don't have to call
InitializeAsync()
from your constructor. It is executed by the xunit framework once per run.
@Deffiss According to IAssebmlyFixture documentation I need to put initialization code into constructor. 😔 See https://github.com/JDCain/Xunit.Extensions.AssemblyFixture#:~:text=public%20DatabaseFixture()
You probably have a deadlock in this part code:
public EnvironmentFixture()
{
_environmentName = "test";
Task.WaitAll(InitializeAsync());
}
This will certainly fire in a CI environment. The only way I managed to share the context across different classes is to initialize it once in the first test and store it in a separate class as context. Subsequent tests will check whether it was initialized. And if it was then it will reuse it.
@dmitry-kosar I confirm you do not need to call OnInitializeAsync
from the constructor.
In our case, we initialize a logger, but not the environment itself.
public TestEnvironmentFixture()
{
Logger = new TestLogger<TestEnvironmentFixture>();
}
I suppose this is just a typo, to write environmentTwoFixture where you mean environmentFixture
public class MyTests : IAssemblyFixture<EnvironmentFixture>
{
private readonly EnvironmentFixture _environmentFixture;
public DirectIntegrationQueryTests(EnvironmentFixture environmentFixture)
{
_environmentFixture = environmentFixture;
// _environmentFixture = environmentTwoFixture;
}
….
Finally I managed to make it work using IColletionFixture
[CollectionDefinition("Environment collection")]
public class EnvironmentCollection : ICollectionFixture<EnvironmentFixture> { }
[Collection("Environment collection")]
public class MyTests
{
private readonly EnvironmentFixture _environmentFixture;
public MyTests(EnvironmentFixture environmentFixture)
{
_environmentFixture = environmentFixture;
}
...
I’m having an issue when using IAssemblyFixture(from https://www.nuget.org/packages/Xunit.Extensions.AssemblyFixture) for EnvironmentFixture. I works fine on my local machine, but not on CI pipeline. It does not throw any error it just runs and does not end.
Also IClassFixture works fine, but I want to share environment between several tests.
Here is GitHub action
Usage
EnveronmentFixture
I have mongo, redis and kafka containers registering following way