Reputation: 13
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:spring/integration-test.xml"
})
@TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
public class TestClass {
@Autowired
private Dao dao;
@Test
@Transactional
public void test1() {
}
}
Hello! I'm trying to start single test method from Spring Tool Suite Debug configurations and I have an exception:
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test1], {ExactMatcher:fDisplayName=test1(com.org.TestClass )], {LeadingIdentifierMatcher:fClassName=com.org.TestClass ,fLeadingIdentifier=test1]] from org.junit.internal.requests.ClassRequest@302e67
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
But since I remove @RunWith(SpringJUnit4ClassRunner.class) at this example the test method launched successfully.
I would appreciate any useful advice to eliminate this trouble. Thank you.
I have spring version 3.1.1
Here are imports:
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import org.testng.annotations.Test;
Upvotes: 1
Views: 1222
Reputation: 241
It is cause spring configuration specific works.
Spring created proxy instance for your class because of @Transactional
annotation under your test method, and after that method doesn't contain @Test
annotation.
Please see information about spring proxy there: https://spring.io/blog/2012/05/23/transactions-caching-and-aop-understanding-proxy-usage-in-spring
Do you really need @Transactional
annotation under your test method?
You can create class-helper only for testing, write @Transactional
annotated methods there, inject it (annotation @Autowired
) and use in your test class
Upvotes: 1