Svish
Svish

Reputation: 158081

Different flavors of JUnit?

I'm trying to fresh up my Java and also to learn how to use Maven and JUnit. Following the Maven quick start I ran the following in the console:

mvn archetype:generate \
 -DgroupId=com.mycompany.app \
 -DartifactId=my-app \
 -DarchetypeArtifactId=maven-archetype-quickstart \
 -DinteractiveMode=false

I then got a simple App.java and an AppTest.java in their proper folders. I'm now looking at the AppTest.java and trying to figure out how to use this JUnit stuff. The problem is that I don't understand it, and I looks quite different from what I see for example in the JUnit Cookbook. For example the version I got from Maven has different package names and there is no annotation of the test method.

What's going on here? Is Maven using something else than regular JUnit? Or is it just doing something fancy?


More info

Apache Maven 3.0.2 (r1056850; 2011-01-09 01:58:10+0100)
Java version: 1.6.0_23, vendor: Sun Microsystems Inc.

AppTest.java

package com.mycompany.app;

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);
    }

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

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Upvotes: 0

Views: 420

Answers (1)

lweller
lweller

Reputation: 11317

no maven uses regular Junit.

But here the old version 3.8.1 is used (that works without annotations, in so does not require java 5 or higher).

Simply update you junit dependency to newest junit version (4.8.2) and then you can write tests as you are used to wirh annotations.

Upvotes: 5

Related Questions