For running Protractor end to end tests in xunit I want to Combine Class Fixtures and Collection Fixtures in xunit.
I created a collection fixture DatabaseServerFixture[Collection]
to run the database and Server, so the database and web services are available for all tests all the time and database/server setup is only done once for all tests for faster execution.
I've set up a second BrowserFixture
to share one instance of a browser between all tests in one class, since I want to be able to run tests from different classes parallel, each class owning it's own browser class.
Problem is: I need to reference the BrowserFixture
to use in my test classes, so I can't reference the DatabaseServerFixture
. And since the DatabaseServerFixture
is never referenced, it is not created => no database, so all tests are failing.
I don't need to be able to Access the DatabaseServerFixture
from my tests, but I Need it to start before all tests. How do I get xunit to start it even though it seems I'm not using it anywhere?
I tried creating a dummy test which uses the DatabaseServerFixture
, but it is not running for the other tests, so it didn't help.
I had a similar need which was complicated by the fact that the class fixture needed information from the collection fixture for initialization. Although I couldn't find it documented in xUnit, it appears that the dependency injection can handle this case just fine. I was able able to get it to work as follows (using your classes as an example):
public class BrowserFixture: IDisposable {
public BrowserFixture(DatabaseServerFixture dbFixture) {
// BrowserFixture initialization with dbFixture dependencies.
}
public void Dispose(){}
}
[Collection("DatabaseServerFixtureCollection")]
public void BrowserTests: IClassFixture<BrowserFixture> {
public BrowserTests(
DatabaseServerFixture dbFixture,
BrowserFixture browserFixture) {
// BrowserTests initialization here.
}
}
This is similar to what Mickaël Derriey had mentioned, but with the additional injection of the DatabaseServerFixture
into the BrowserFixture
which I find to be a common use case. Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With