Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running JUnit tests with Maven under Eclipse

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!

like image 842
Olivier Grégoire Avatar asked Mar 27 '11 19:03

Olivier Grégoire


People also ask

How do I run a Maven JUnit test in Eclipse?

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. Hint: By default surefire looks for files with *Test.

How do I run a JUnit test case in Maven?

We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.


1 Answers

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.

like image 172
cpater Avatar answered Sep 19 '22 06:09

cpater