0

I use Spring + TestNg + Spring Test DBUnit.

Right now I ran into the issue that Spring Test DBUnit @DatabaseSetups annotation is executed early than TestNG @BeforeMethod annotation.

I need to change this behavior to let methods annotated with TestNG @BeforeMethod to be executed first and only then methods with @DatabaseSetups.

Right now I have the following test class:

@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DbUnitTestExecutionListener.class })
public abstract class BaseTest extends AbstractTestNGSpringContextTests {


    @BeforeMethod(alwaysRun=true)
    public void setUp() {
        //do setup logic
    }

    @AfterMethod(alwaysRun=true)
    public void tearDown() {
        // do tearDown logic
    }

...
}

Is there any way with Spring @TestExecutionListeners to change the order of the processing? How to configure these classes in order to execute all @BeforeMethod first?

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • Are you sure about this? The method `com.github.springtestdbunit.DbUnitRunner#beforeTestMethod()` which is responsible for working with the `@DatabaseSetups` annotation is being invoked from within `com.github.springtestdbunit.DbUnitTestExecutionListener#beforeTestMethod()` which is again being invoked only from within `org.springframework.test.context.TestContextManager#beforeTestMethod()` which is invoked from within `org.springframework.test.context.testng.AbstractTestNGSpringContextTests#springTestContextBeforeTestMethod()` which is a `@BeforeMethod` – Krishnan Mahadevan Nov 01 '17 at 04:41
  • @KrishnanMahadevan thanks for your answer. I apologize, I missed the very crucial part of my code in the question. I have updated it now. The issue is that logic inside my custom `setUp/tearDown` methods is executed right after the logic defined by `DatabaseSetups`/`DatabaseSetup` annotations.How to synchronize them in order to be able to execute this logic in the proper order? – alexanoid Nov 01 '17 at 06:41

0 Answers0