Reputation: 22516
I'm trying to run JUnit tests on a spring project on Maven build or install.
The test class in src/main/test:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:mvc-dispatcher-servlet.xml",
"classpath:appContext.xml",
"classpath:databaseContext.xml"})
public class Test {
@Autowired
private EventService evtService;
@org.junit.Test
public void test1(){
List<String> eventNames = evtService.getEventNames();
Assert.assertTrue(eventNames.size() > 0);
}
}
In the POM:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
When I run the Test class from eclipse with Run as -> JUnit test it works fine, but when I run Maven Install for example I get:
T E S T S
-------------------------------------------------------
Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=10, useUnlimitedThreads=false
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Versions: JUnit: 4.11; Spring: 3.2.3.RELEASE
Upvotes: 2
Views: 3021
Reputation: 97527
If your mentioning in your quesiton is correct The test class in src/main/test
than this is the simple problem, cause test have to be located into /src/test/java
instead.
Upvotes: 4
Reputation: 27536
Do you inherit this POM from some parent?Because this configuration of the surefire-plugin
is probably in your parent, causing your tests to be skipped.
<configuration>
<skipTests>true</skipTests>
</configuration>
So you need either to remove the skipTests
property from your parent or explicitly allow tests in child project.
Upvotes: 1