✅ Integration testing, database transaction
hi
i'm learning about dotnet test tools, using xunit
i have a web app, i want to write some integration tests for it
my controllers change data, so i want to rollback the changes after each test.
since i can't pass the db context to controllers, i'm thinking how i can achieve this
I've found TransactionScope which i think will move everything to transaction automatically, but i'm not sure
will this do what i intend?
TransactionScope Class (System.Transactions)
Makes a code block transactional. This class cannot be inherited.
3 Replies
there are tools like https://github.com/jbogard/Respawn and testcontainers to clean or reset your db after tests
GitHub
GitHub - jbogard/Respawn: Intelligent database cleaner for integrat...
Intelligent database cleaner for integration tests - jbogard/Respawn
You can also use a WebApplicationFactory to spawn the endpoint
And then access the db context in the same process to clean up afterwards
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View