14

I just installed the plugin m2e for the first time on Eclipse.

I wrote a simple JUnit (version 4) test. I can run it from Eclipse, but not from the pom.xml (alt-click, Run as, Maven Test). I suppose I need to tell Maven to search for that class, but I just don't know how.

Also, I couldn't find JUnit 4 in the groupId "junit": only the version 3.8.1 is available. Do I really need to write tests for version 3.x and not version 4+?

How to fix this?

Think of me as a newbie with Maven: that's exactly what I am. So please don't speak about artifact technobabble unless describing exactly what I need to do. I could barely install Guava as dependency and I'm completely lost right now with these concepts.

Thanks!

Olivier Grégoire
  • 33,839
  • 23
  • 96
  • 137
  • Note that Maven has two independent class locations and only looks for tests in one, and Eclipse merges the two. This mean that it is possible to write tests that pass when run inside Eclipse and fail from the command line. – Thorbjørn Ravn Andersen Jun 12 '14 at 12:12

2 Answers2

17

you can run Junit 4 with Maven. You just need the Junit 4 dependency in your pom. You also need the surefire plugin to execute the tests.

See: http://maven.apache.org/plugins/maven-surefire-plugin/

Hint: By default surefire looks for files with *Test.java naming to find tests.

renzo
  • 135
  • 1
  • 2
  • 10
cpater
  • 1,049
  • 10
  • 12
3

Add this to your pom.xml

<project>
  [...]
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.18.1</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  [...]
</project>

run maven with clean test

Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71