Reputation: 540
I'm using maven version 3.5.2 and seemingly have correct dependencies:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.devtop</groupId>
<artifactId>discount-calculator</artifactId>
<version>0.1</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<!--Testing dependencies-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.1.2.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.27.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</build>
</project>
However when I run mvn clean test
it can't find any tests, and simply prints out:
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ discount-calculator ---
[INFO] No tests to run.
My tests classes do end with word "Test" and are properly annotated, I can run them through intellij, but maven seems to have problems
One of the test classes I have in package residing in <projectDir>/src/main/test
:
package com.devtop.discountcalculator.discount;
import com.devtop.discountcalculator.RuleReturnsTrue;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class RuleChainFactoryTest {
@Test
public void testChainRules_oneRule_exception() {
assertThrows(IllegalArgumentException.class,
() -> RuleChainFactory.getInstance().chainRules(new RuleReturnsTrue()));
}
}
Upvotes: 0
Views: 1202
Reputation: 25966
Maven favors convention over configuration, and has standard directory layout. By default, it expects tests in src/test/java.
Check Introduction to the Standard Directory Layout. The defaults are defined in the super POM.
The defaults can be overriden (if you have good reason to do so).
Upvotes: 3