Created
August 10, 2013 13:44
-
-
Save odrotbohm/6200481 to your computer and use it in GitHub Desktop.
Sample code to show apparent bug in Spring test context framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Transactional | |
public class ConcreteTest extends TestBase { | |
@Before | |
public void setUp() { | |
// Create sample data in the database | |
} | |
// Further test methods | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringJunit4ClassRunner.class) | |
@ContextConfiguration(…) | |
public abstract class TestBase { | |
@Test | |
public void commonTest() { | |
} | |
} |
This is the same issue discussed in the following JIRA ticket:
The problem here is that for the tests executed in
ConcreteTest
thesetUp(…)
method is not executed in a transaction for thecommonTest()
method.
That is true for commonTest()
(since it is not declared as transactional, either at the method or class level), but all other test methods declared in ConcreteTest
would have setUp()
executed within their transactions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem here is that for the tests executed in
ConcreteTest
thesetUp(…)
method is not executed in a transaction for thecommonTest()
method. It feels like the@Transactional
annotation is not found as the declaring class of the test method is inspected but not the currently executed test class.