[Question] Database not cleared automatically between tests
See original GitHub issueI am struggling with Rider for the fact that database is never cleared and its state is shared across different test classes, creating some major issues. And I am wondering if I am not using it correctly or is an issue. I am following the example of Quarkus. The main issue I am finding is tests failing because the data set cannot initialized, because some other test inserted data that prevents some table from being fully deleted.
- For example, let’s have 3 tables: A, B & C, where B & C have a FK to A’s id.
A’s data in initialized with a yml data set using
@DataSet
. - In one test on it’s own class I insert a registry in C, and don’t delete it. Be it an accident or just because the test failed for some other reason and the manual deletion was not executed.
- Then, any tests that uses A’s dataset fails to start with a message like this
should_delete_all_B Time elapsed: 0.074 s <<< ERROR!
com.github.database.rider.core.exception.DataBaseSeedingException: Could not initialize dataset: a.yml
Caused by: org.h2.jdbc.JdbcSQLException:
Referential integrity constraint violation: "FKJYATY0XA5P7DMGQP41FYB0SNE: PUBLIC.C FOREIGN KEY(A_ID) REFERENCES PUBLIC.A(ID) (1011)"; SQL statement:
delete from A [23503-197]
You see this forces to go through all tests trying to find where this data is inserted. It could be a failing test, or just a new test that does not clear it’s data.
Seeing this comment https://github.com/database-rider/database-rider/issues/68#issuecomment-359396449, I think we agree data should be reseted on every test, however that’s not the case.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
Hi @abelsromero, with this PR you can specify cleanBefore in a
@BeforeEach
callback which would result in cleaning db before every test, eg:I know you would like a way to override defaults but this can help your usecase.
Note that the annotation will be used most of the time because datasets may change between tests