开发者

Running JUnit tests with Maven under Eclipse

开发者 https://www.devze.com 2023-02-19 22:20 出处:网络
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 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 dep开发者_如何学JAVAendency and I'm completely lost right now with these concepts.

Thanks!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消