Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tip clarifying that @Transactional is not applicable to @BeforeClass methods #456

Closed
wants to merge 1 commit into from

Conversation

asaikali
Copy link
Contributor

@asaikali asaikali commented Feb 5, 2014

This tip is needed because when using @BeforeClass with TestNG tests unlike JUnit by the time @BeforeClass is called the whole application context is setup and and dependency injection is working therefore as a user it easy to assume that @transactional should be working but it dose not work and then you waste lots of time trying to figure out why, until you make a call to TransactionSynchronizationManager.isActualTransactionActive() and discover that @Transactional is not supposed to be used with @BeforeClass when working with TestNG

For example

@ContextConfiguration(locations = { "classpath:test.xml" })  
@Transactional
@TransactionConfiguration(defaultRollback = true)
@ActiveProfiles({ "development", "standalone", "test-db" })
public class TransactionalTest extends AbstractTransactionalTestNGSpringContextTests
{
    @BeforeClass
    @Transactional
     public void setupDB()
     {
          // the following assert fails before there is no TX
          assertThat(TransactionSynchronizationManager.isActualTransactionActive()).isTrue(); 
          // do some stuff that needs a tx
     }
}

@sbrannen
Copy link
Member

sbrannen commented Mar 9, 2018

Hi @asaikali,

I realize this PR has been opened quite some time, so I apologize for that.

However, would you be willing to apply your change to the relocated testing chapter document in master?

If so, I'd be happy to merge that in.

Cheers

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 24, 2019
@sbrannen sbrannen added in: test Issues in the test module type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 22, 2019
@sbrannen sbrannen added this to the 5.2 M1 milestone Feb 22, 2019
@sbrannen sbrannen changed the title Add trip clarifying that @Transactional is not applicable to @BeforeClass methods Add tip clarifying that @Transactional is not applicable to @BeforeClass methods Feb 22, 2019
@sbrannen
Copy link
Member

Related to #16024

@sbrannen sbrannen closed this in b4fc7b4 Feb 22, 2019
sbrannen added a commit that referenced this pull request Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: documentation A documentation task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants