Java Reference
In-Depth Information
As you can see in the declaration of the maven-compiler-plugin in the previous
listing, we haven't set the groupId parameter. That's because the maven-compiler-
plugin is one of the core Maven plug-ins that has a org.apache.maven.plugins
groupId , and as we mentioned at the beginning of the chapter, plug-ins with such
a groupId can skip it.
10.3.2
Maven Surefire plug-in
Ant uses the javac task to compile the tests that we've selected, the same way Maven uses
the maven-compiler-plugin to compile all of the source code that's in src/main/java/.
The same thing happens with the process of unit testing your project; Ant uses the junit
task and executes the test cases that we've selected , whereas Maven uses—guess what?—
a plug-in. The Maven plug-in that executes the unit tests is called maven-surefire-plugin .
Notice the italics in the previous sentence; the Surefire plug-in is used to execute the
unit tests for your code, but these unit tests aren't necessarily JU nit tests. There are also
other frameworks for unit testing, and the Surefire plug-in can execute their tests, too.
The conventional way to start the maven-surefire-plugin is simple. All you need to
do is invoke the test phase of Maven. This way Maven will first invoke all of the phases
that are supposed to come before the test phase (validate and compile phases) and
then invoke all of the plug-ins that are attached to the test phase, thus invoking the
maven-surefire-plugin . So by calling
mvn clean test
Maven first cleans the target/ directory, then compiles the source code and the tests,
and finally executes all of the tests that are in the src/test/java directory (remember
the convention). The output should be similar to that shown in figure 10.3.
That's great, but what if we don't want to execute all of our tests? What if we want
to execute only a single test case? Well, this is something unconventional, so we need to
configure the maven-surefire-plugin to do it. Hopefully there's a parameter for the
plug-in that allows us to specify a pattern of test cases that we want to be executed. The
configuration of the Surefire plug-in is done in the same way as the configuration of
the Compiler plug-in, and it's shown in listing 10.8.
Listing 10.8
Configuration of the maven-surefire-plugin
<build>
<plugins>
[...]
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>**/Test*.java</includes>
</configuration>
</plugin>
[...]
</plugins>
</build>
 
 
 
 
 
 
Search WWH ::




Custom Search