I have inherited a project which has over 100 Junit test classes. The problem is the unit test sources and main source files are in the same folder.There is no src/test/java folder.This can be built with ant, but with maven I am not able to get maven run the tests unless I refactor every test in to src/test folder. Is there a way to specify the a directory other than src/test/java from where mvn can run the tests?
Is it at all possible to execute 'mvn test' when tests are in src/main/java and not in src/test/java
Asked
Active
Viewed 285 times
-1
-
4You simply need to move the unit tests to the `src/test/java` folder you can use the same package names etc. – khmarbaise Sep 06 '13 at 10:17
-
1Answer to a similar question http://stackoverflow.com/questions/8986915/surefire-doesnt-launch-test-in-src-main-java – LaurentG Sep 06 '13 at 11:22
-
Probably written using Eclipse that treated the two the same. – Thorbjørn Ravn Andersen Apr 26 '22 at 16:35
1 Answers
1
Move the tests into src/test
. If you've inherited the project then it's time to fix mistakes.
From src/test
, generate a list of test classes. If there's a naming convention:
find . -name 'Test*.java' -or -name '*Test.java' >../test-classes
If they're all using JUnit:
fgrep -lR 'junit.' >../test-classes
Then move those files into src/test
by scripting your scm.

Joe
- 29,416
- 12
- 68
- 88