英文:
No Tests Were Executed when using JUnit5 and Spring-boot-starter-parent
问题
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Piece to be disabled for tests to run -->
<!-- <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
<!-- </parent> -->
<groupId>com.hmhco</groupId>
<artifactId>crs-v2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crs-v2</name>
<description>Content Recommendation Service V2</description>
<properties>
<java.version>1.8</java.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
</project>
import org.junit.jupiter.api.Test;
public class TestingTest {
@Test
public void checking() {
System.out.println("checking------------");
}
}
谢谢。
英文:
I have a very simple JUnit test class that I can not run unless I remove parent spring-boot-starter-parent
from the pom, which wouldn't be a possibility for our production application. The error we get on is No Tests Were Executed and below is the mvp with the parent piece that whenever not commented out would block the tests. If I can get any guidance to know how to fix this please.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Piece to be disabled for tests to run -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hmhco</groupId>
<artifactId>crs-v2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>crs-v2</name>
<description>Content Recommendation Service V2</description>
<properties>
<java.version>1.8</java.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
<maven.surefire.version>3.0.0-M5</maven.surefire.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
</project>
import org.junit.jupiter.api.Test;
public class TestingTest {
@Test
public void checking() {
System.out.println("checking------------");
}
}
Thank you.
答案1
得分: 1
问题与您尝试使用不同版本的JUnit Jupiter有关。spring-boot-parent(2.2.4.RELEASE)预定义的版本是5.5.2。最简单的解决方案是删除junit-jupiter部分的版本(版本标签),并使用从spring-boot-parent继承的版本。我能给出的最好建议是从新版本的Spring Boot(最新版本为2.3.3.RELEASE)开始,该版本使用了更新的JUnit版本。
如果您无法这样做,您必须使用junit-bom
文件,如下所示:
<!-- language:language-xml -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
然后它应该正常工作。之后,您在pom.xml文件中不再需要定义版本标签来使用依赖项。
英文:
The problem is related to that you trying to use a different version of junit jupiter. The version which is predefined by spring-boot-parent (2.2.4.RELEASE) is 5.5.2. The simplest solution is to remove the versions of junit-jupiter parts (version tag) and use the one which is inherited from spring-boot-parent. The best recommendation I can give is to start with a newer version of Spring Boot (2.3.3.RELEASE most recent one) which uses a more recent version.
If you can't go that way you have to use the junit-bom
file instead like this:
<!-- language:language-xml -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Then it should work fine. Afterwards you have to use the dependencies without defining the version tag anymore in your pom.xml file.
答案2
得分: -1
将-DfailIfNoTests=false添加到mvn命令中似乎使其工作正常。
英文:
Adding -DfailIfNoTests=false to the mvn command seems to make it work.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论