Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a single test in maven -> No tests were executed

When I run a single test in Maven with this command:

mvn test -Dtest=InitiateTest 

I'm getting the following result:

No tests were executed! 

It worked a couple of minutes ago, but now it stopped working for some reason. I tried running mvn clean a couple of times before running the test, it doesn't help.

The test looks like this:

import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; import org.junit.After; import org.junit.Before; import org.junit.Test;  public class InitiateTest {      public static FirefoxDriver driver;      @Before         public void setUp() throws Exception {             driver = new FirefoxDriver();     }      @Test     public void initiateTest() throws Exception {             driver.get("http://localhost:8080/login.jsp");             ...     }      @After     public void tearDown() throws Exception {         driver.close();     } } 

UPDATE:

It's caused by adding this dependency to POM:

<dependency>    <groupId>org.seleniumhq.selenium</groupId>    <artifactId>selenium</artifactId>    <version>2.0b1</version>    <scope>test</scope> </dependency> 

When I remove it, everything works fine. Everything works fine even when I add these two dependencies instead of the previous one:

<dependency>    <groupId>org.seleniumhq.selenium</groupId>    <artifactId>selenium-support</artifactId>    <version>2.0b1</version>    <scope>test</scope> </dependency> <dependency>    <groupId>org.seleniumhq.selenium</groupId>    <artifactId>selenium-firefox-driver</artifactId>    <version>2.0b1</version>    <scope>test</scope> </dependency> 

This is weird.

like image 684
John Manak Avatar asked Jan 10 '11 10:01

John Manak


People also ask

How do you run a single test case in Maven?

The Maven surefire plugin provides a test parameter that we can use to specify test classes or methods we want to execute. If we want to execute a single test class, we can execute the command mvn test -Dtest=”TestClassName”.

Why your JUnit 5 tests are not running under Maven?

Prior to these releases, to run JUnit 5 tests under Maven, you needed to include a JUnit provider dependency for the Maven Surefire plugin. This is correct for pre 2.22. 0 releases of Maven Surefire/Failsafe.


2 Answers

Perhaps you are seeing this bug, which is said to affect surefire 2.12 but not 2.11?

like image 72
joel truher Avatar answered Sep 22 '22 07:09

joel truher


You are probably picking up JUnit3 on your classpath somewhere, which effectively disables JUnit4.

Run mvn dependency:tree to find out where it's coming in from and add an exclude to the dependency.

like image 23
krosenvold Avatar answered Sep 22 '22 07:09

krosenvold