-
-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection Fixture Support #673
Comments
not a fan of collection fixtures due to two reasons:
so, we won't be adding any support for collection-fixtures in the however, i believe for your scenario, an AssemblyFixture would be a good fit. i've added our own (more convenient) version of assembly-fixture support in here's how to use it:
// somefile.cs
[assembly: EnableAssemblyFixtures]
//same old AppFixture base but, lifecycle of the fixture becomes different
//turns into a singleton for the whole test run.
public class GlobalApp : AppFixture<Program>
{
protected override async Task PreSetupAsync()
{
//triggered once for the whole test run
//before any test-classes are executed
}
protected override async Task SetupAsync()
{
//triggered once for the whole test run
//after the WAF has been instantiated
}
protected override async Task TearDownAsync()
{
//triggered once for the whole test run
//when all test-classes have been executed
}
}
//all test-classes receive the same derived GlobalApp instance
public class TestClassA(GlobalApp App) : TestBaseWithAssemblyFixture<GlobalApp>
{
}
public class TestClassB(GlobalApp App) : TestBaseWithAssemblyFixture<GlobalApp>
{
} that's it... give it a whirl and let me know how it goes. i'm not familiar with respawn. so if the above doesn't seem to work with respawn, could you possibly provide a repro project i can debug and see what's going on? thanks! |
Sorry I didn't explain the full problem. I need to be able to do 1 time setup/teardown to manage the DB connection but I also need each test using the fixture to reset the DB to a known state before the test execution. Because of this, it's required that they also run serially so they don't step on each other. Assembly fixture works great for the 1 time setup/teardown but (if I'm reading the doc correctly) the tests will run in parallel unless I disable parallelization for the whole assembly (would prefer not). I'll still give it a try and report back but I'm guessing this can only be solved with a custom collection. |
okie i think i've got it with [CollectionDefinition(Name)]
public class MyTestCollection : TestCollection<MyAppFixture>
{
public const string Name = nameof(MyTestCollection);
}
[Collection(MyTestCollection.Name)]
public class TestClassA(MyAppFixture App) : TestBase
{
...
}
[Collection(MyTestCollection.Name)]
public class TestClassB(MyAppFixture App) : TestBase
{
...
} |
I was just about to report back when I saw this new addition, gave it a try and it works perfectly. About as clean as you can get when working with collections, I love it! I'm very quickly becoming a big fan of FE and of you, Thank you! |
you're most welcome and thanks for the feedback! |
Hi,
New to FE here, but I was curious if we could get some support for Collection Fixtures. I was hoping to have something with a similar contract to
TestBase
with Setup/TearDown and Faker instance but not have to create that myself.The problem
I'd like to set up and open a DB connection before any integration tests run and close it when they've all completed (for use with Respawn).
What I tried
PreSetupAsync
on the AppFixture works ok to set up the connection but since it's invoked before the WAF, I can't be lazy and use it to get my connection string. Regardless I didn't see any way to TearDown once after all tests have completed. If possible to add, that would be a fine solution, but I didn't see any easy ways for FE to implement that.Possible Addition
A new test base class that doesn't implement
IClassFixture
.Usage
The text was updated successfully, but these errors were encountered: