简体   繁体   中英

Testng && Spring context unit test -> execute sql before and after test method

When using JUnit a SpringRunner, there is an awesome feature of executing scripts before and after any test method

@Test
    @SqlGroup([
            @Sql(scripts = ["classpath:clean_db.sql", "populate_data.sql"]),
            @Sql(scripts = ["classpath:clean_db.sql"], executionPhase = AFTER_TEST_METHOD)
    ])

However, when using testngframework and running spring-context tests, this annotation doesn't work because testng uses AbstractTestNGSpringContextTests instead of SpringRunner

Is there any similar annotation in testng or any other util to execute scripts before and after tests?

Is there a reason why executing the script in the TestNG annotations @AfterTest or @AfterMethod (depending what you need) wouldn't work?

The first one would run after all the tests under a suite run, and the second, after each test method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM