[英]Why my test are being ignored generating coverage report with Jacoco and Maven
I have the follwowing POM file:我有以下 POM 文件:
<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>target\site\jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.junit.reportPaths>target\surefire-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>
</dependencies>
</project>
I have created some tests.我创建了一些测试。 One of them, for example, test some functions from Passenger class.其中之一,例如,测试来自乘客 class 的一些功能。 It code is the following:它的代码如下:
package es.ull.passengers;
import es.ull.flights.Flight;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PassengerTest {
Passenger Pasajero = new Passenger("1","Paco","US");
Flight testing = new Flight("AA9020", 100);
@Test
public void test_get_Name(){
System.out.println("Testing get Name...");
assertEquals("Paco", Pasajero.getName());
}
@Test
public void test_get_Identifier(){
System.out.println("Testing get Identifier...");
assertEquals("1", Pasajero.getIdentifier());
}
@Test
public void test_get_CountryCode(){
System.out.println("Testing get Country Code...");
assertEquals("US", Pasajero.getCountryCode());
}
@Test
public void test_Flight(){
System.out.println("Testing get Flight...");
Pasajero.setFlight(testing);
assertEquals(testing, Pasajero.getFlight());
}
@Test
public void test_join_flight(){
System.out.println("Testing join Flight...");
Flight testing2 = new Flight("AA9023", 200);
Pasajero.joinFlight(testing2);
assertEquals(testing2, Pasajero.getFlight());
}
@Test
public void test_to_string(){
System.out.println("Testing toString...");
assertEquals("Passenger Paco with identifier: 1 from US", Pasajero.toString());
}
}
When I do "mvn verify", it generates the index.xml on targe/site.当我执行“mvn verify”时,它会在目标/站点上生成 index.xml。 However, when I checked it, it looks like this:但是,当我检查它时,它看起来像这样:
So, I want to know why is this happening.所以,我想知道为什么会这样。 Why isn´t considering my tests??为什么不考虑我的测试? Here is the console output:这是控制台 output:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.manning.junitbook:ch13-continuous >----------------
[INFO] Building ch13-continuous 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ch13-continuous ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\jesus\Downloads\Airport\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ch13-continuous ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ch13-continuous ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ch13-continuous ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ ch13-continuous ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running FlightTest
Testing number of passengers...
Testing removing Passenger...
Testing adding Passenger...
Testing flight number...
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.031 s - in FlightTest
[INFO] Running PassengerTest
Testing get Flight...
Testing toString...
Testing get Country Code...
Testing get Name...
Testing get Identifier...
Testing join Flight...
[INFO] Tests run: 6, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 s - in PassengerTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 10, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ch13-continuous ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.8.5:report (report) @ ch13-continuous ---
[INFO] Loading execution data file C:\Users\jesus\Downloads\Airport\target\jacoco.exec
[INFO] Analyzed bundle 'ch13-continuous' with 2 classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.520 s
[INFO] Finished at: 2020-12-12T13:27:22Z
[INFO] ------------------------------------------------------------------------
Is annotation @Test imported from package org.junit.jupiter.api.Test?注解@Test是从package org.junit.jupiter.api.Test导入的吗?
If that's the case, you need add maven plugin maven-surefire-plugin in pom file.如果是这种情况,您需要在 pom 文件中添加 maven 插件 maven-surefire-plugin 。
Here's maven junit5 plugin document这里是maven junit5插件文档
I think junit5 doesn't work without maven-surefire-plugin when execute maven test.我认为 junit5 在执行 maven 测试时没有 maven-surefire-plugin 无法工作。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.