gstackoverflow
gstackoverflow

Reputation: 36984

make spring test method NOT transactional

I have this class

@TransactionConfiguration(defaultRollback = false)
public class CandidateServiceTest extends AbstractServiceTest {
        @Test
    public void add() {
        }
}


@ContextConfiguration(locations = { "classpath:/test/BeanConfig.xml" })
public class AbstractServiceTest  extends AbstractTransactionalJUnit4SpringContextTests{
 ...
}

There are exist way that method add() was not transactional ?

Upvotes: 0

Views: 1769

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136022

You can annotate a test method with org.springframework.test.annotation.Rollback annotation with true or false arg

Upvotes: 0

Tom Verelst
Tom Verelst

Reputation: 15992

You can use the @NotTransactional annotation.

@TransactionConfiguration(defaultRollback = false)
public class CandidateServiceTest extends AbstractServiceTest {

    @Test
    @NotTransactional
    public void add() {
        ...
    }
}

EDIT

Since @NotTransactional is deprecated, Spring documentation suggests that you split the transactional and non-transactional tests in different classes.

Upvotes: 2

Related Questions