I have integration tests. But before running all the tests, I have to insert general data. They are needed only for tests, for example, add all rights for a particular user. Of course, I cannot set up a production database with these rights.
As a solution, I created a separate dbunit file with common data that should be inserted before running all the tests: "common_inserts.xml" But the problem is that I don’t want to duplicate the code and add this file to each test class, too much duplication.
I also have an abstract base test from which absolutely all tests are inherited. And it would be right to add a common data insert in this class:
@Transactional
@SpringBootTest
@RunWith(SpringRunner.class)
@TestExecutionListeners(value = {
TransactionalTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class
}, mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
@DatabaseSetup({"/dbunit/common_inserts.xml"})
public abstract class AbstractCommonIntegrationTest {
// ...
}
@DatabaseSetup({"/dbunit/my_test.xml"})
public class MyTest extends AbstractCommonIntegrationTest {
// not inserted data from "/dbunit/common_inserts.xml"
}
But the problem is it doesn't work! No data is inserted that was specified in the abstract base class. Is it possible to solve this problem?
I have integration tests. But before running all the tests, I have to insert general data. They are needed only for tests, for example, add all rights for a particular user. Of course, I cannot set up a production database with these rights.
As a solution, I created a separate dbunit file with common data that should be inserted before running all the tests: "common_inserts.xml" But the problem is that I don’t want to duplicate the code and add this file to each test class, too much duplication.
I also have an abstract base test from which absolutely all tests are inherited. And it would be right to add a common data insert in this class:
But the problem is it doesn't work! No data is inserted that was specified in the abstract base class. Is it possible to solve this problem?