How do I execute tests on my project?
Author: Deron Eriksson
Description: This tutorial describes how to execute junit tests on a maven project.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page: < 1 2

(Continued from page 1)

Now, let's create an External Tool Configuration for "mvn test". If we select a project and execute the "mvn test" configuration, it will execute all of the phases of the mavenSW build lifecycles up to and including the test phase for the selected project.

External Tool Configuration for 'mvn test'

The first time I execute "mvn test", maven downloads all of the necessary resources and then executes the tests.

Console output from first execution

If I execute "mvn test" on the mytest project again, we see the following output.

Console output from second execution

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building mytest
[INFO]    task-segment: [test]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test]
[INFO] Surefire report directory: C:\dev\workspace\mytest\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.maventest.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.039 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Jan 31 18:04:05 PST 2008
[INFO] Final Memory: 3M/7M
[INFO] ------------------------------------------------------------------------

As you can see from the console output, "mvn test" executes the unit tests for the selected project.

Page: < 1 2