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 >

The mavenSW build lifecycle can be broken down into several phases, one of which is the "test" phase in which unit testing is performed. If JUnit tests are present in the src/test directory, they will be executed during the test phase of the maven build lifecycle. Therefore, if we'd like to execute the test phase (and all the steps of the maven build lifecycle up to the test phase), we can call the "test" phase via the following maven command:

mvn test

More information about the maven build lifecycle can be found at http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html.

In the "mytest" project, there is an AppTest unit test class.

AppTest in 'mytest' project

AppTest can be seen here.

AppTest.java

package com.maventest;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
 * Unit test for simple App.
 */
public class AppTest 
    extends TestCase
{
    /**
     * Create the test case
     *
     * @param testName name of the test case
     */
    public AppTest( String testName )
    {
        super( testName );
    }

    /**
     * @return the suite of tests being tested
     */
    public static Test suite()
    {
        return new TestSuite( AppTest.class );
    }

    /**
     * Rigourous Test :-)
     */
    public void testApp()
    {
        assertTrue( true );
    }
}

(Continued on page 2)

Page:    1 2 >