Maven handles java unit tests well by defaulting to:
src/test/java
We're writing quite a few Groovy unit tests right now, and I'd like to find a way in Maven to specify a folder such as:
src/test/groovy
as a test folder. This would help us to import a Maven project into, say, IntelliJ, without additional setup.
Someone mentioned this was possible, but I wasn't able to find a way searching the Maven docs, or SO. Does anyone know how to mark the directory in the pom?
Thank you
Update: I am not asking how to run the tests in Maven! The tests are already running fine. I'm asking how to mark the directories as test directories in Maven.
As per the Maven configurations, tests class will be found in the src/test directory and the source code will be found in the src/main directory. So src/main/java is the root directory for your source code & src/test/java/ is the root directory for your test code.
The target directory is used to house all output of the build. The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.
We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.
The Maven directory structure is a standard directory structure which Maven expects to build a project. You do not have to follow the Maven directory structure, but it is much easier if you do, and it also makes it easier for other developers to understand your project directory structure.
As described at http://maven.apache.org/ref/3.3.3//maven-model/maven.html#class_build the build section of the pom.xml has an entry to specify the test folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With