Skip to content

Commit df7b24b

Browse files
committed
Allow non-public @transactional test methods
Prior to this commit, the TransactionalTestExecutionListener required @transactional test methods to be public; however, neither TestNG nor JUnit 5 require that @test methods are public. Consequently, non-public transactional test methods silently run *without* a transaction. This commit removes the 'public' restriction on transactional test methods by setting the 'publicMethodsOnly' flag in AnnotationTransactionAttributeSource to false. Issue: SPR-14000
1 parent 197434b commit df7b24b

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
136136
@SuppressWarnings("deprecation")
137137
private static final TransactionConfigurationAttributes defaultTxConfigAttributes = new TransactionConfigurationAttributes();
138138

139-
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource();
139+
// Do not require @Transactional test methods to be public.
140+
protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false);
140141

141142
@SuppressWarnings("deprecation")
142143
private TransactionConfigurationAttributes configurationAttributes;

spring-test/src/test/java/org/springframework/test/context/testng/AnnotationConfigTransactionalTestNGSpringContextTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void setUp() throws Exception {
135135
}
136136

137137
@Test
138-
public void modifyTestDataWithinTransaction() {
138+
void modifyTestDataWithinTransaction() {
139139
assertInTransaction(true);
140140
assertAddPerson(JANE);
141141
assertAddPerson(SUE);

spring-test/src/test/java/org/springframework/test/context/testng/ConcreteTransactionalTestNGSpringContextTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void setUp() throws Exception {
205205
}
206206

207207
@Test
208-
public void modifyTestDataWithinTransaction() {
208+
void modifyTestDataWithinTransaction() {
209209
assertInTransaction(true);
210210
assertAddPerson(JANE);
211211
assertAddPerson(SUE);

0 commit comments

Comments
 (0)