@After ,@before not working in testcase
The AbstractTransactionalDataSourceSpringContextTests
class forces the use of the old JUnit 3.x syntax, which means that any of the JUnit 4 annotation will not work.
Your method runBare()
is executed not because of the @Before
annotation, but because it is named runBare()
, which is a method provided by ConditionalTestCase
and JUnit TestCase
class.
So you have 2 solutions:
- Use the AlexR answer to use JUnit 4 tests and Spring;
- Keep your inheritance of
AbstractTransactionalDataSourceSpringContextTests
, but use theonSetUp
andonTearDown
methods instead of the@Before
and@After
methods.
Use @BeforeEach
instead of @Before
and @AfterEach
instead of @After
.