Skip to content

Instantly share code, notes, and snippets.

@odrotbohm
Created August 10, 2013 13:44
Show Gist options
  • Save odrotbohm/6200481 to your computer and use it in GitHub Desktop.
Save odrotbohm/6200481 to your computer and use it in GitHub Desktop.
Sample code to show apparent bug in Spring test context framework
@Transactional
public class ConcreteTest extends TestBase {
@Before
public void setUp() {
// Create sample data in the database
}
// Further test methods
}
@RunWith(SpringJunit4ClassRunner.class)
@ContextConfiguration(…)
public abstract class TestBase {
@Test
public void commonTest() {
}
}
@odrotbohm
Copy link
Author

The problem here is that for the tests executed in ConcreteTest the setUp(…) method is not executed in a transaction for the commonTest() 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.

@sbrannen
Copy link

This is the same issue discussed in the following JIRA ticket:

https://jira.springsource.org/browse/SPR-7824

@sbrannen
Copy link

The problem here is that for the tests executed in ConcreteTest the setUp(…) method is not executed in a transaction for the commonTest() 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