Running JUnit 4 Tests in Maven

December 8, 2010

I was trying to convert my JUnit tests to JUnit-4-style annotations, and they would run fine individually in Eclipse, but the Maven Surefire plugin wasn’t running them properly. Seems that it was running them using a JUnit 3 runner, because it detected tests by finding methods with “test” at the start of the method name, but ignored @Test and @Before annotations.

I read a number of articles online about how to fix this, but what they said didn’t work. Eventually, I found that I had to add the following entry exactly (can’t omit junitArtifactName, or add a version number to it).


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.6</version>
<configuration>
<includes>
<include>**/Test*.java</include>
</includes>
<junitArtifactName>junit:junit</junitArtifactName>
</configuration>
</plugin>
</code>

Advertisements

Sample App 0.1 Released

February 10, 2009

I’ve just posted a Java webapp called “Sample App” (until I can think of a better name for it). The goal for this webapp is to be a project template using industry-standard libraries and best-practices for full-stack Java application development, from a high-performance rich client tier, back to the database. There’s nothing particularly revolutionary about it, but it’s hard to find this particular combination of features – especially a combined rich frontend and backend. It’s released under a BSD license.

sample-app-0.1.zip

Check it out, take what’s helpful to you, and improve on the rest!

Features

  • Client
    • Logging (YUI Logger)
    • Combination of assets to save on HTTP requests
    • CSS sprites automatically generated (SmartSprites)
    • Minification (YUI Compressor)
    • Ajax requests (YUI Connection)
    • Strict presentation logic boundary (JSTL)
    • Copy in properties files
    • Object-oriented JavaScript
    • Event binding performed by JavaScript, not in markup
  • Server
    • Separation of business logic and webapp into distinct projects
    • Dependency injection (Spring)
    • Unit testing (JUnit)
    • MVC (Struts configured via Spring)
    • ORM (Hibernate)
    • Logging (Log4J)
    • Separate Business Logic and DAO tiers
  • Build
    • Separate build targets for dev and prod environments, changing config files, adding additional JS, and enabling/disabling logging and minification
    • Run on local box from a bare checkout using a build target, without any additional configuration or native code (Jetty, HSQLDB)

Requirements:

  • JDK 1.5 or above
  • Ant 1.6.5 or above

Getting Started:

Download the zip file above, expand it, go to sample-webapp/build, and run ant. This will run the default target run-dev. The app will then be accessible on your local computer at http://localhost:8080/sample-webapp/