我无法在 Maven 中使用 mvn 测试运行我的测试



我有以下POM:

<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.manning.junitbook</groupId>
<artifactId>ch13-continuous</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ch13-continuous</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<sonar.coverage.jacoco.xmlReportPaths>targetsitejacocojacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.junit.reportPaths>targetsurefire-reports</sonar.junit.reportPaths>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>

</build>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>

</dependencies>

我有一个测试叫做";飞行测试";以及";PassengerTests";分别进入我的目录/test/java/es.ull/fflights和/test/java/es.ull/passenger。然而,当我在IntelliJ上启动mvn测试时,它最终显示了以下内容:

[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

为什么会发生这种情况??我认为它不能本地化我的测试,但我不知道为什么。

您有一些名为"飞行测试";以及";PassengerTests";这就是问题所在,你能把名字改成";FlightTest";以及";PassengerTest",通过删除末尾的s,否则它将无法识别测试。我已经核实了。

也许您可以尝试使用新版本。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>*Test.java</include>
</includes>
</configuration>
</plugin>

你也可以使用jupiter和尝试junit5与jupiter dependencies。例如,使用jupiter依赖项中的@Test注释。

最新更新