I’m a bit confused whether I’m doing this right because every resource I google for has a different way of setting it up.
Some of them initialize the dbContext right in the test class, some do in the WebAppFactory’s ConfigureServices (or is it ConfigureTestServices?).
Some do it in the IAsyncLifetime’s InitializeAsync, some do it as a dependency injection and other examples just put it as a member variable in the factory.
I don’t wanna code dump my project here and ask for someone to solve it but I am not sure anymore what to do. My current attempt is using an sqlite database and it is breaking when I try to run all the tests at the same time due to this.
Makes sense since they are all using the same db in this case so I tried following a guide and just letting them use the :memory: one but that one, for some reason, doesn’t seem to initialize the database at all and tests fail because the database doesn’t have any tables.
I also added a CollectionDefinition with an ICollectionFixture for each individual test class (one per controller so far) thinking this might cause each test to have its own separate database (or factory?) but that didn’t really do anything.
I’m hoping someone experienced can probably immediately recognize what am I missing, or at the very least give me a solid resource that I could read to figure this out, but any help is appreciated.
Doesn’t that contradict?
You can’t have the single DB reset at the beginning of tests if the tests run concurrently.
You are probably right and I just misunderstood fixtures / collections and how they work. I am now trying to configure it using postgres testcontainers and just letting each test create its own but facing a bunch of other issues so not even sure how this works anymore, seems like every tutorial has a different approach. Some just put all the code for creating containers in the setup/dispose of the test class itself instead of trying to be smart with the WebApplicationFactory fixtures and maybe I just end up doing that
I’m sure you have to launch the integration tests in some way parameterized. Why can’t you make the DB data source depend on that parameter[ization]?
I’m not sure if you’re past the DB concern now or not.