Services are not a part of DatabaseFixture. All we need is to up and run contaner to get connection string which will be passed to Services on the test class level. Here is what we did in our project . Separate static class for database container which has TestContainer MsSqlBuilder - it runs one db container per assembly via static reference DataBaseFixture - test class which creates a database with the name of T (separate database for every test class but in the same dbContainer) DatabseFixture InitializeAsync and DisposeAsync for Respawner CreateAsync/ResetAsync TestClass InitializeAsync - get dbEntity Faker, generate items, resolve DbContext - AddRange - SaveChanges(). When resolving dbContext Services already has connectionstring to dbContainer and nameof(T) as a Database name So in the end we have 1 container per assembly and every class of the assembly has its own database which is refreshed after every test method has run. It allows us to run all tests in parallel without any side effects
Really useful. Thanks. By the way. Does this format here leads to a tricky scenario where one test may change the data in the database that other tests will see, right? I did something once that created a snapshot after publishing the database and restored this snapshot before each test.
Are you using a tool that removes all the pauses and gaps? I can see all the jumps in your face. It feels you're talking non stop for 15 minutes! I find this tiring when listening in this manner. Is the goal to make the video shorter? I don't mind if it's like 3 minutes longer if you're talking in a natural way. I noticed this trend with several TH-camrs. Ugh! Anyway, thanks for the tutorial.
I have an editor work with me to take out the mistakes and some of the pauses. Usually the videos are 2-3x the length without the editing. We might be too aggresive on the removals. I'll look at that. Thanks for supporting the channel.
Thanks a ton, very clear very nice and i am thankful for the public repo!
Good to see you back Shawn!
Services are not a part of DatabaseFixture. All we need is to up and run contaner to get connection string which will be passed to Services on the test class level.
Here is what we did in our project .
Separate static class for database container which has TestContainer MsSqlBuilder - it runs one db container per assembly via static reference
DataBaseFixture - test class which creates a database with the name of T (separate database for every test class but in the same dbContainer)
DatabseFixture InitializeAsync and DisposeAsync for Respawner CreateAsync/ResetAsync
TestClass InitializeAsync - get dbEntity Faker, generate items, resolve DbContext - AddRange - SaveChanges(). When resolving dbContext Services already has connectionstring to dbContainer and nameof(T) as a Database name
So in the end we have 1 container per assembly and every class of the assembly has its own database which is refreshed after every test method has run. It allows us to run all tests in parallel without any side effects
Not a bad strategy. In xUnit 3 you'll be able to doing assembly-level fixtures which is essentially what you're doing.
Thank you! Glad to have you back!
Really useful. Thanks.
By the way. Does this format here leads to a tricky scenario where one test may change the data in the database that other tests will see, right?
I did something once that created a snapshot after publishing the database and restored this snapshot before each test.
Depends on the scope, but yes. (Not a solution for unit tests). But you could scope the container to be rerun on every test, or use fixtures
Thanks Master Shawn, where can get the free SQL database hosting?
No where I know.
@@swildermuth 😅
awesome
That's good
No source code for this 😅?
Just added it to the description: github.com/shawnwildermuth/codingshorts/tree/main/testingwithcontainers
Are you using a tool that removes all the pauses and gaps? I can see all the jumps in your face. It feels you're talking non stop for 15 minutes! I find this tiring when listening in this manner. Is the goal to make the video shorter? I don't mind if it's like 3 minutes longer if you're talking in a natural way. I noticed this trend with several TH-camrs. Ugh! Anyway, thanks for the tutorial.
I have an editor work with me to take out the mistakes and some of the pauses. Usually the videos are 2-3x the length without the editing. We might be too aggresive on the removals. I'll look at that. Thanks for supporting the channel.