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

16

33

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.

Emilio answered 10/1, 2011 at 10:52 Comment(2)
What kind of test are you trying to run? You did not put an @Ignore by any chance?Prang
Probably not too helpful..but remember, both those are beta products and mightily subject to breaking all over the place.Phyllis
A
13

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 exclude if from the dependency.

Armelda answered 10/1, 2011 at 19:45 Comment(0)
H
13

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

Heir answered 26/4, 2012 at 19:11 Comment(7)
Thanks, this is what I was running into. I ended up using 2.12.3 which contains a fix.Underset
Seconded, 2.12.3 contained the fix for this.Lafountain
Apparently also 2.19.1 carries the bug :(Lingle
it helps me too, really caused by the testng conflict with selenium internal version . thanks . take to use surefire 2.19.1 ,no problem now .Ruscher
Link is dead and no summary in answer, so this answer is almost pointless now.Fraternal
With 2.19.1 I was able to run a single test, with 2.19 I've got the "No tests were executed!" error.Extrasensory
fixed the link.Heir
C
6

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>
Cubital answered 11/1, 2011 at 20:23 Comment(1)
It was the same for me a minute a go... or an hour before I found this :/ THX manParlor
P
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

Printable answered 30/4, 2020 at 14:57 Comment(1)
wow! 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? :/Whisenhunt
G
3

I have changed "maven-surefire-plugin" to 2.14.1 version (from 2.12) and it helped

Georgiegeorgina answered 1/6, 2013 at 22:13 Comment(0)
E
1

Had a similar problem adding jtestr dependency. It turns out one of its dependencies was picking up junit-3.8.1. I solved it using the exclusion statement below

<dependency>
  <groupId>org.jtestr</groupId>
  <artifactId>jtestr</artifactId>
  <exclusions>
   <exclusion>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
   </exclusion>
  </exclusions>
  <version>0.6</version>
  <scope>test</scope>
</dependency> 
Eastereasterday answered 2/10, 2011 at 21:5 Comment(0)
U
1

In my case, I was running a single test using mvn test -Dtest=MyTest. My mistake was that the only test had its @test annotation commented out so no test was being found in the file by junit. Doh!

Unbent answered 23/1, 2014 at 15:56 Comment(0)
E
1

changed from 2.6 to 2.18.1 and things work now

Emalia answered 21/4, 2016 at 19:17 Comment(0)
I
1

In the build session of the pom.xml, include this:

 <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.14.1</version>
     </plugin>
    </plugins>
  </build>
Interval answered 16/6, 2016 at 13:58 Comment(1)
indeed my pom.xml was missing maven-surefire-plugin entry entirely, so I skipped the other suggestions about the plugin versions - my badWhisenhunt
M
1

I had a similar issue. So I had to build the project from project's root level using

mvn clean install -DskipTests=True

And then run the test command from the directory where test package's pom was residing

mvn test -Dtest=TestClass

Also make sure that value of skip option is true. For example in my pom file, the default value of skip is true.

 <properties>
    <skipTests>true</skipTests>
</properties>


<build>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <skip>${skipTests}</skip>
            </configuration>
    </plugin>
</build>

So when I run the maven test, I set it to false

mvn test -Dtest=TestUserUpdate* -DskipTests=false
Myrlmyrle answered 15/6, 2017 at 14:53 Comment(0)
C
1

update the org.apache.maven.plugins:maven-surefire-plugin to 2.22.0, it was resolved.

Cervantes answered 13/11, 2019 at 11:43 Comment(1)
Welcome to StackOverflow.Please note this type of answer should be in a comment.Aldrich
J
0

Try running maven in debug mode. It might give you more information.

mvn -X -Dtest=InitiateTest test
Josi answered 10/1, 2011 at 11:1 Comment(0)
S
0

I had this issue when duplicating and refactoring a test from a different class.

The issue was annotating a private method with @Test, causing it to be ignored, changing to public fixed the issue. :facepalm:

    @Test
    public void testImportOrderItems() {
Siler answered 16/11, 2020 at 19:23 Comment(0)
Q
-1

Maybe as useless as my last attempt, but I just read a JUnit 4 test class should import org.junit.Test.* and org.junit.Assert.* to be considered so. As you don't have the Assert import, it might be worth trying this quickly just to be sure...

Qualitative answered 10/1, 2011 at 12:21 Comment(0)
E
-2
mvn test -Dtest='xxxx.*Test' -Dmaven.test.failure.ignore=true  -DfailIfNoTests=false

I have meet the same question that No tests were executed! My suggestion is add another paramters that -Dmaven.test.failure.ignore=true -DfailIfNoTests=false can solve it.

Erythrocyte answered 21/3, 2017 at 2:33 Comment(1)
Ensuring that the error is not ignored does absolutely nothing to prevent the error from occurring.Hickson
Q
-3

I don't really how the @Test annotation processes your test, but can you try prefixing your test method with "test"?

public void testInit() throws Exception {
      driver.get("http://localhost:8080/login.jsp");
      ...
}
Qualitative answered 10/1, 2011 at 11:4 Comment(2)
@Test annotation was introduced in jUnit 4, in jUnit 3 every method had to start with "test"Disquietude
yep, that unfortunately doesn't help. @Test annotation is enough.Emilio

© 2022 - 2024 — McMap. All rights reserved.