【发布时间】:2019-09-04 19:21:25
【问题描述】:
我使用的是 maven 3.5.2 版,并且似乎具有正确的依赖关系:
<?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>
但是,当我运行 mvn clean test 时,它找不到任何测试,只是打印出来:
[INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ discount-calculator ---
[INFO] No tests to run.
我的测试类确实以单词“Test”结尾并且注释正确,我可以通过 intellij 运行它们,但是 maven 似乎有问题
我在包中的一个测试类位于<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()));
}
}
【问题讨论】:
-
省略
spring-test框架是否有效? -
@Sormuras - nop
-
你能确定一下
2.22.1吗?根据github.com/junit-team/junit5-samples/blob/r5.5.0-M1/…,它确实适用于木星5.5.0-M1 -
没有工作,即使使用 junit-jupiter 工件而不是引擎
-
请出示您的测试课程?
标签: maven unit-testing junit maven-surefire-plugin junit5