By Zugwalt


2011-05-30 16:20:33 8 Comments

I have a maven program, it compiles fine. When I run mvn test it does not run any tests (under TESTs header says There are no tests to run.).

I've recreated this problem with a super simple setup which I will include below as well as the output when run with -X.

The unit tests run fine from eclipse (both with its default junit package and when I instead include the junit.jar downloaded by maven). Also mvn test-compile correctly creates the class under test-classes. I am running this on OSX 10.6.7 with Maven 3.0.2 and java 1.6.0_24.

Here is the directory structure:

/my_program/pom.xml
/my_program/src/main/java/ClassUnderTest.java
/my_program/src/test/java/ClassUnderTestTests.java

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>my_group</groupId>
    <artifactId>my_program</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>My Program</name>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

ClassUnderTest.java:

public class ClassUnderTest {

    public int functionUnderTest(int n) {
        return n;
    }

}

ClassUnderTestTests.java:

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class ClassUnderTestTests {

    private ClassUnderTest o;

    @Before
    public void setUp() {
        o = new ClassUnderTest();
    }

    @Test
    public void testFunctionUnderTest_testCase1() {
        Assert.assertEquals(1, o.functionUnderTest(1));
    }

    @Test
    public void testFunctionUnderTest_testCase2() {
        Assert.assertEquals(2, o.functionUnderTest(2));
    }
}

End of mvn -X test:

[DEBUG] Configuring mojo org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-surefire-plugin:2.7.1, parent: [email protected]]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.7.1:test' with basic configurator -->
[DEBUG]   (s) basedir = /Users/aaron/Programs/my_program
[DEBUG]   (s) childDelegation = false
[DEBUG]   (s) classesDirectory = /Users/aaron/Programs/my_program/target/classes
[DEBUG]   (s) disableXmlReport = false
[DEBUG]   (s) enableAssertions = true
[DEBUG]   (s) forkMode = once
[DEBUG]   (s) junitArtifactName = junit:junit
[DEBUG]   (s) localRepository =        id: local
      url: file:///Users/aaron/.m2/repository/
   layout: none

[DEBUG]   (f) parallelMavenExecution = false
[DEBUG]   (s) pluginArtifactMap = {org.apache.maven.plugins:maven-surefire-plugin=org.apache.maven.plugins:maven-surefire-plugin:maven-plugin:2.7.1:, org.apache.maven.surefire:surefire-booter=org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile, org.apache.maven.surefire:surefire-api=org.apache.maven.surefire:surefire-api:jar:2.7.1:compile, org.apache.maven.surefire:maven-surefire-common=org.apache.maven.surefire:maven-surefire-common:jar:2.7.1:compile, org.apache.maven.shared:maven-common-artifact-filters=org.apache.maven.shared:maven-common-artifact-filters:jar:1.3:compile, org.codehaus.plexus:plexus-utils=org.codehaus.plexus:plexus-utils:jar:2.0.5:compile, junit:junit=junit:junit:jar:3.8.1:compile, org.apache.maven.reporting:maven-reporting-api=org.apache.maven.reporting:maven-reporting-api:jar:2.0.9:compile}
[DEBUG]   (s) printSummary = true
[DEBUG]   (s) project = MavenProject: my_group:my_program:1.0-SNAPSHOT @ /Users/aaron/Programs/my_program/pom.xml
[DEBUG]   (s) projectArtifactMap = {junit:junit=junit:junit:jar:4.8.1:test}
[DEBUG]   (s) redirectTestOutputToFile = false
[DEBUG]   (s) remoteRepositories = [       id: central
      url: http://repo1.maven.org/maven2
   layout: default
snapshots: [enabled => false, update => daily]
 releases: [enabled => true, update => never]
]
[DEBUG]   (s) reportFormat = brief
[DEBUG]   (s) reportsDirectory = /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG]   (s) session = [email protected]
[DEBUG]   (s) skip = false
[DEBUG]   (s) skipTests = false
[DEBUG]   (s) testClassesDirectory = /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   (s) testFailureIgnore = false
[DEBUG]   (s) testNGArtifactName = org.testng:testng
[DEBUG]   (s) testSourceDirectory = /Users/aaron/Programs/my_program/src/test/java
[DEBUG]   (s) trimStackTrace = true
[DEBUG]   (s) useFile = true
[DEBUG]   (s) useManifestOnlyJar = true
[DEBUG]   (s) workingDirectory = /Users/aaron/Programs/my_program
[DEBUG] -- end configuration --
[INFO] Surefire report directory: /Users/aaron/Programs/my_program/target/surefire-reports
[DEBUG] Setting system property [user.dir]=[/Users/aaron/Programs/my_program]
[DEBUG] Setting system property [localRepository]=[/Users/aaron/.m2/repository]
[DEBUG] Setting system property [basedir]=[/Users/aaron/Programs/my_program]
[DEBUG] Using JVM: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-junit4:jar:2.7.1:test (selected for test)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:test (selected for test)
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-junit4/2.7.1/surefire-junit4-2.7.1.jar Scope: test
[DEBUG] Adding to surefire test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: test
[DEBUG] Test Classpath :
[DEBUG]   /Users/aaron/Programs/my_program/target/test-classes
[DEBUG]   /Users/aaron/Programs/my_program/target/classes
[DEBUG]   /Users/aaron/.m2/repository/junit/junit/4.8.1/junit-4.8.1.jar
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10 for /Users/aaron/.m2/repository
[DEBUG] dummy:dummy:jar:1.0 (selected for null)
[DEBUG]   org.apache.maven.surefire:surefire-booter:jar:2.7.1:compile (selected for compile)
[DEBUG]     org.apache.maven.surefire:surefire-api:jar:2.7.1:compile (selected for compile)
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-booter/2.7.1/surefire-booter-2.7.1.jar Scope: compile
[DEBUG] Adding to surefire booter test classpath: /Users/aaron/.m2/repository/org/apache/maven/surefire/surefire-api/2.7.1/surefire-api-2.7.1.jar Scope: compile
Forking command line: /bin/sh -c cd /Users/aaron/Programs/my_program && /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -jar /Users/aaron/Programs/my_program/target/surefire/surefirebooter6118081963679415631.jar /Users/aaron/Programs/my_program/target/surefire/surefire4887918564882595612tmp /Users/aaron/Programs/my_program/target/surefire/surefire9012255138269731406tmp

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
There are no tests to run.

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.089s
[INFO] Finished at: Mon May 30 12:03:09 EDT 2011
[INFO] Final Memory: 7M/62M
[INFO] ------------------------------------------------------------------------

27 comments

@edubriguenti 2019-09-12 19:59:12

I struggle with this problem. In my case I wasn't importing the right @Test annotation.

1) Check if the @Test is from org.junit.jupiter.api.Test (if you are using Junit 5).

2) With Junit5 instead of @RunWith(SpringRunner.class), use @ExtendWith(SpringExtension.class)

import org.junit.jupiter.api.Test;

@ExtendWith(SpringExtension.class)
@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource(locations = "classpath:application.properties")    
public class CotacaoTest {
    @Test
    public void testXXX() {

    }
}

@Michael Hegner 2019-06-24 15:51:20

In my case we are migration multimodule application to Spring Boot. Unfortunately maven didnt execute all tests anymore in the modules. The naming of the Test Classes didnt change, we are following the naming conventions.

At the end it helped, when I added the dependency surefire-junit47 to the plugin maven-surefire-plugin. But I could not explain, why, it was trial and error:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
  <dependency>
    <groupId>org.apache.maven.surefire</groupId>
    <artifactId>surefire-junit47</artifactId>
    <version>${maven-surefire-plugin.version}</version>
  </dependency>
</dependencies>

@Mark W 2019-05-17 14:59:04

Another easily overlooked problem - Ensure your class' file has the .java extension

@A. S. Ranjan 2019-03-05 22:29:20

Following worked just fine for me in Junit 5

https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.0</version>
        </plugin>
    </plugins>
</build>
<!-- ... -->
<dependencies>
    <!-- ... -->
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.4.0</version>
        <scope>test</scope>
    </dependency>
    <!-- ... -->
</dependencies>
<!-- ... -->

@walkeros 2019-01-27 19:31:38

Such problem might occur when you use surfire plugin 3.x.x+ with JUnit5 and by mistake annotate the test class with @Test annotation from JUnit4.

Use: org.junit.jupiter.api.Test (JUnit5) instead of org.junit.Test (Junit4)

NOTE: this might be hard to notice as the IDE might run this wihout problems just as JUnit4 test.

@teyzer 2018-04-17 14:58:03

UPDATE:

Like @scottyseus said in the comments, starting from Maven Surefire 2.22.0 the following is sufficient:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
</plugin>

When using JUnit 5, i ran into the same problem. Maven Surefire needs a plugin to run JUnit 5 tests. Add this to our pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0-M1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0-M1</version>
        </dependency>
    </dependencies>
</plugin>

Source: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven

@Arya Pourtabatabaie 2018-09-24 19:22:04

I'm getting a "not found" for junit-platform-surefire-provider.

@scottyseus 2018-12-11 17:23:05

Note that with Surefire 2.22, it shouldn't be necessary to add dependencies on the surefire-provider or jupiter-engine artifacts. My tests seem to run fine without them, at least. see this answer.

@austince 2019-02-13 20:10:27

It is also worth noting that you must use org.junit.jupiter.api.Test instead of org.junit.Test when using this plugin or the tests will not be found.

@João Matos 2018-12-28 19:19:53

Many of these answers were quite useful to me in the past, but I would like to add an additional scenario that has cost me some time, as it may help others in the future:

Make sure that the test classes and methods are public.

My problem was that I was using an automatic test class/methods generation feature of my IDE (IntelliJ) and for some reason it created them as package-private. I find this to be easier to miss than one would expect.

@AlexC 2019-01-05 19:26:24

This is the problem I had also, for some reason IntelliJ is creating tests as package-private and Maven cannot see them. Changing the class and @Test method to public made maven execute the tests.

@lamino 2019-06-26 19:48:40

Solved my problem! Note that this doesn't apply to JUnit 5+. I guess IntelliJ's code generator assumes you're using the latest version.

@SudhirKumar 2019-09-21 05:45:01

@lamino I was using junit5 and it was failing because my test method was not public

@Wecherowski 2019-10-19 22:29:27

A bit cheeky from IntelliJ to tell me that the methods can be package-private ..

@ShayneR 2018-12-11 04:13:16

I faced the same issue , it resolved by below change in pom.xml :

<build>
    <testSourceDirectory>test</testSourceDirectory>

...

changed to:

<build>
    <testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>

@Prasetyo Budi 2018-11-18 12:45:51

i used using this code

<sourceDirectory>src_controller</sourceDirectory>
  <testSourceDirectory>src_test</testSourceDirectory>

to my pom.xml, just ensure that testng file in specific there

<suiteXmlFile>/Users/mac/xxx/xxx/xx.xxxx.xx/xxx.restassured.xx/testng.xml</suiteXmlFile>

@Duc Tran 2018-11-08 18:59:15

In my case it was adding the junit-vintage-engine which makes it compatible with older version of JUnit tests and can run them. As I'm using JUnit 5.

<dependency>
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <scope>test</scope>
</dependency>

@Duc Tran 2019-09-09 18:00:30

I think SpringBoot only includes what it uses. It makes sense that you have to specify your dependencies according to your needs. Otherwise, you'll be importing a whole bunch of libraries which you don't use.

@user3470629 2019-11-22 05:02:49

this worked for me. thanks

@youhans 2018-10-13 08:26:00

If you have written your tests in JUnit 4 and added JUnit 5 dependencies to the surefire plugin, your tests will not run.

In that case, just comment JUnit 5 dependencies from surefire plugin:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <!--<dependencies>-->
                <!--<dependency>-->
                    <!--<groupId>org.junit.platform</groupId>-->
                    <!--<artifactId>junit-platform-surefire-provider</artifactId>-->
                    <!--<version>1.0.0</version>-->
                <!--</dependency>-->
                <!--<dependency>-->
                    <!--<groupId>org.junit.jupiter</groupId>-->
                    <!--<artifactId>junit-jupiter-engine</artifactId>-->
                    <!--<version>${junit.version}</version>-->
                <!--</dependency>-->
            <!--</dependencies>-->
        </plugin>

@anon58192932 2018-08-15 04:02:04

Here's the exact code I had to add to my pom.xml:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.21.0</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.2.0-M1</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.2.0</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

And here's my dependencies:

    <dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert-core</artifactId>
        <version>2.0M10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.2.0-M1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0-M1</version>
    </dependency>
</dependencies>

@datv 2018-05-03 10:39:34

One more tip (in addition to the previous answers):

In Eclipse, go to your project's Properties > click Run/Debug Settings:

"This page allows you to manage launch configurations with the currently selected resource"

In there you can add (New...) or remove (Delete) any JU (JUnit) tests you have in your project (under the src/test/java folder, or course).

@Saikat Sengupta 2018-04-17 18:26:15

If your test class name does not follow the standard naming convention (as highlighted by @axtavt above), you need to add the pattern/class name in the pom.xml in order to Maven pick the test -

...
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*_UT.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build> 
...

@hizmarck 2018-03-20 05:22:48

In case someone has searched and I do not solve it, I had a library for different tests:

<dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${org.junit.jupiter.version}</version>
        <scope>test</scope>
    </dependency>

When I installed junit everything worked, I hope and help this:

<dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

@Boris Z. 2018-02-23 08:49:14

/my_program/src/test/java/ClassUnderTestTests.java

should be

/my_program/src/test/java/ClassUnderTestTest.java

The Maven finds those ends Test or starts with Test to run automatically.

However, you can using

mvn surefire:test -Dtest=ClassUnderTestTests.java 

to run your tests.

@Rusi Popov 2017-09-02 17:14:11

Another reason for not running the test cases happened to me - I had a property named "test" for completely different purposes, but it interfered with the surefire plugin. Thus, please check your POMs for:

<properties>
  <test>.... </test>
  ...
</properties>

and remove it.

@rajesh madhavan 2017-08-10 15:37:46

I also had similar issue, after exploring found that testng dependency is causing this issue. After removing the testng dependency from pom (as I dont need it anymore), it started to work fine for me.

    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8</version>
        <scope>test</scope>
    </dependency>

@hogi 2017-11-04 11:21:27

Removing testng solved the issue for me, but why?

@Tuomas Kiviaho 2017-04-14 09:27:22

junitArtifactName might also be the case if the JUnit in use isn't the standard (junit:junit) but for instance...

<dependency>
    <groupId>org.eclipse.orbit</groupId>
    <artifactId>org.junit</artifactId>
    <version>4.11.0</version>
    <type>bundle</type>
    <scope>test</scope>
</dependency>

@robjwilkins 2017-02-28 09:45:55

Maven will not run your tests if the project has <packaging>pom</packaging>

You need to set the packaging to jar (or some other java artefact type) for the tests to run: <packaging>jar</packaging>

@axtavt 2011-05-30 16:25:19

By default Maven uses the following naming conventions when looking for tests to run:

  • Test*
  • *Test
  • *TestCase

Your test class doesn't follow these conventions. You should rename it or configure Maven Surefire Plugin to use another pattern for test classes.

@Tobias Kremer 2013-09-10 11:37:41

I find it more appealing to change the maven config. This naming convention does pose some danger to unexpirienced user. Naming your testcases like SomethingTest1, SomethingTest2 would result in the tests silently not beeing executed. Maven can not do this for backwards compatibility but it does seam more logic to search for testcases in all files.

@demaniak 2014-05-05 10:24:45

I never knew this - had two cases that ended with "Tests", and maven refused to run them...changed to "Test", and all is well in the lollipop guild again. Thanks.

@berezovskyi 2014-07-11 14:31:23

@Tobias, naming tests like SomethingTest1, SomethingTest2 should not only result in the tests silently not beeing executed, but having the person who named them that way killed as well ;)

@Angad 2014-12-29 20:42:09

@Tobias I agree with your point about the danger imposed with naming convention. It kind of also breaks the pattern implied by the use of annotations. An implicit result of using annotations is that classes/methods having a specific annotation can be searched. I would have hoped that Maven did not put in place the naming convention restriction and instead relied only on scanning @Test annotated methods in any class.

@tokosh 2016-03-28 05:44:10

In my case a parent maven has the pattern set to *Tests. It took me a long time to find that.

@J E Carter II 2017-05-10 18:11:08

Importantly, the class name must follow the naming convention. MyTests.java fails while MyTest.java is found.

@Adam Taras 2017-09-07 12:07:40

+1 Configure Maven Surefire Plugin: See Inclusions and Exclusions of Tests for a precise example

@Gareth 2017-10-13 09:54:22

Note that the surefire documentation now claims that **/*Tests.java is a default include!

@datv 2018-05-03 10:47:12

@demaniak Same here, 4 years later. Renaming the class name to end with Test instead of Tests did the magic.

@dynex 2018-07-31 11:49:20

Question: So why annotate with @test if you have to follow Test* convention anyway?

@AlexPes 2019-04-30 08:59:13

Additionally to that, make sure that you do not have a mix of Junit4 and Junit5 Annotations used in the tests. In my case, i have to test classes in the same package. The first test class (with Junit5 Annotations/@Test) is executed , but the second one was not, since I blindly added @Test (by Alt+Enter) and it apppeared to be Junit4. After replacing it with Junit5 - both tests run

@Harvey Lin 2019-10-14 21:37:10

Tobias was right, I was wondering why my tests won't run, turns out it is a stupid way of how Maven looks for what qualifies as a test class.

@Robin Ma 2013-04-05 13:51:32

I also found that the unit test code should put under the test folder, it can not be recognized as test class if you put it under the main folder. eg.

Wrong

/my_program/src/main/java/NotTest.java

Right

/my_program/src/test/java/MyTest.java

@dinesharjani 2017-05-22 18:28:49

Thaaank you! This and setting the scope to test (<scope>test<scope>) in the pom.xml file did it for me.

@Bruck Wubete 2019-11-08 17:00:35

I ran into this, watch out for tests vs test. The proper one is test

@user1016765 2015-10-28 10:52:40

Discovered if you prefix a test with 'Abstract' it will be ignored by default aswell.

@Antoine Meyer 2017-11-29 15:52:37

maven.apache.org/guides/getting-started ``` And the default excludes are: */AbstractTest.java */AbstractTestCase.java ```

@Collin Krawll 2018-03-01 06:06:33

It also seems to ignore */TestAbstractSomeClassName.java.

@Jon 2015-06-22 17:24:38

Another thing that can cause Maven to not find the tests if if the module's packaging is not declared correctly.

In a recent case, someone had <packaging>pom</packaging> and my tests never ran. I changed it to <packaging>jar</packaging> and now it works fine.

@morsor 2017-11-15 07:51:13

Excellent suggestion! Demonstrates the dangers of 'copy-paste' when splitting a single-module Maven artifact into multiple.

@Arun Avanathan 2019-05-04 22:46:20

I wish maven printed a message - package type is pom - so not running tests - to give some clue to the developers :(

@Mitra 2015-01-06 08:22:50

Check that (for jUnit - 4.12 and Eclipse surefire plugin)

  1. Add required jUnit version in POM.xml in dependencies. Do Maven -> Update project to see required jars exported in project.
  2. Test class is under the folder src/test/java and subdirectories of this folder (or base folder can be specified in POM in config testSourceDirectory). Name of the class should have tailng word 'Test'.
  3. Test Method in the test class should have annotation @Test

@Paul 2015-05-29 13:39:39

This is more of a java config issue, but in addition to naming the test class properly and putting the test file in the test directory under src, the package name of the test class must match the package name of the class you are testing.

@Michael K 2015-08-24 18:02:09

@Paul False - Maven will execute all classes matching the convention under src/test/java. The package convention is for structure and to allow tests access to package-private methods.

@t3rmin41 2014-11-02 08:46:23

Also, check if your test classes directory (e.g. src/test/java) corresponds to directory listed in property <testSourceDirectory> in your pom.xml under <build> property. Took me a while to find that.

@bruce szalwinski 2014-03-13 17:19:39

If you have a shared Java / Groovy application and all you have are Groovy unit tests, then Maven won't find any tests. This can be fixed by adding one unit test under src/test/java.

Related Questions

Sponsored Content

27 Answered Questions

[SOLVED] How to add local jar files to a Maven project?

17 Answered Questions

[SOLVED] Maven is not working in Java 8 when Javadoc tags are incomplete

47 Answered Questions

[SOLVED] Does a finally block always get executed in Java?

33 Answered Questions

[SOLVED] How do you assert that a certain exception is thrown in JUnit 4 tests?

18 Answered Questions

[SOLVED] How to run test methods in specific order in JUnit4?

33 Answered Questions

7 Answered Questions

[SOLVED] java.lang.OutOfMemoryError: Java heap space in Maven

1 Answered Questions

[SOLVED] Issues in exceution while run the test script through Maven

  • 2016-05-17 11:15:04
  • Yogesh Trivedi
  • 158 View
  • 0 Score
  • 1 Answer
  • Tags:   maven selenium

0 Answered Questions

Unable to load mojo plugin, A required class is missing

1 Answered Questions

Sponsored Content