Running a single test in maven -> No tests were executed
Solution 1
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.
Solution 2
Perhaps you are seeing this bug, which is said to affect surefire 2.12 but not 2.11?
Solution 3
I had the same problem. It was caused by testng dependency that came with junit3. Just add a exclusion statement for it and tests should work.
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium</artifactId>
<version>2.0b1</version>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
Solution 4
I got this error when trying to use @org.junit.Test
with
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
The correct annotation to be used is @org.junit.jupiter.api.Test
Solution 5
I have changed "maven-surefire-plugin" to 2.14.1 version (from 2.12) and it helped
Related videos on Youtube
John Manak
Updated on July 09, 2022Comments
-
John Manak almost 2 years
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.
-
Navi over 13 yearsWhat kind of test are you trying to run? You did not put an @Ignore by any chance?
-
mezmo over 13 yearsProbably not too helpful..but remember, both those are beta products and mightily subject to breaking all over the place.
-
-
Kennet over 13 years@Test annotation was introduced in jUnit 4, in jUnit 3 every method had to start with "test"
-
John Manak over 13 yearsyep, that unfortunately doesn't help. @Test annotation is enough.
-
yoosiba almost 13 yearsIt was the same for me a minute a go... or an hour before I found this :/ THX man
-
Matt Lachman over 11 yearsThanks, this is what I was running into. I ended up using 2.12.3 which contains a fix.
-
Yinzara about 11 yearsSeconded, 2.12.3 contained the fix for this.
-
Jaroslav Záruba over 7 yearsApparently also 2.19.1 carries the bug :(
-
Alter Hu over 7 yearsit helps me too, really caused by the testng conflict with selenium internal version . thanks . take to use surefire 2.19.1 ,no problem now .
-
Cedric Reichenbach over 7 yearsLink is dead and no summary in answer, so this answer is almost pointless now.
-
svenmeier about 7 yearsWith 2.19.1 I was able to run a single test, with 2.19 I've got the "No tests were executed!" error.
-
joel truher almost 7 yearsfixed the link.
-
Matthew Read over 6 yearsEnsuring that the error is not ignored does absolutely nothing to prevent the error from occurring.
-
Pratik Bhajankar over 4 yearsWelcome to StackOverflow.Please note this type of answer should be in a comment.
-
hello_earth over 3 yearsindeed my pom.xml was missing maven-surefire-plugin entry entirely, so I skipped the other suggestions about the plugin versions - my bad
-
hello_earth over 3 yearswow! didn't expect this at all, and yes, the automatic imports fix makes it easy to import org.junit.Test - what is this Jupiter API anyway? :/
-
Tian Li over 2 yearsExactly the same problem. Saved my day!