Reputation: 406
I'm running project with structure which suppose runtime modules (or plugins however you call it), like C-style .so objects. For now it works only via ClassLoader
, and I'm trying to use maven to test it. I wrote Test.java
and TestModule.java
files in my project's test directory. But maven tries to run both of them instead only Test.java
. How can I specify test files?
P.S. Is there any system for loading modules except ClassLoader
? And new foreign modules must be the projects depends on my core project?
Upvotes: 0
Views: 737
Reputation: 49361
Maven uses the maven-surefire-plugin to run tests. Therefor it executes the test goal.
The includes property defines what classes will be seen as test classes. The default name pattern is:
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*TestCase.java</include>
</includes>
So if you do not want a test to be executed during the maven test phase (maybe because you only want to run this test manually) than change the includes
property or rename your class (e.g. CheckModule instead of TestModule).
If your TestModule.java
is application code and not some kind of test code than do not place it in the test directory. Have a look at the Maven default directory layout and use it if somehow possible.
Upvotes: 2
Reputation: 13057
Maven - as any other build system - needs to distinguish between production and test code. The recommended variant is to separate both classes using the directory structure:
/src
/main
/java
-- your production classes go here
/test
/java
-- your test classes go here
If your project has a different structure, you can change the default behavior in the pom.xml
file (not recommended):
<build>
<sourceDirectory>${basedir}/src/</sourceDirectory>
<testSourceDirectory>${basedir}/test</testSourceDirectory>
<outputDirectory>${basedir}/bin</outputDirectory>
<testOutputDirectory>${basedir}/test-bin</testOutputDirectory>
...
</build>
If you put both, production and test code in the same directory (not good, not good), you can tell Maven to include or exclude classes from running tests:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<includes>
<include>Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
You still need some kind of naming convention to identify the test classes (recommended: for class MyClass
the corresponding test class should be called MyClassTest
):
<includes>
<include>**/*Test.java</include>
</includes>
Upvotes: 4