gpt4 book ai didi

java - JUnit 5 测试未触发并且测试未显示在测试运行程序中

转载 作者:行者123 更新时间:2023-12-02 08:39:49 26 4
gpt4 key购买 nike

我在 VSCODE 上运行 JUnit 5 测试时遇到问题。我相信我的环境设置正确。 junit5-samples 的克隆 | junit5-jupiter-starter-maven 按预期构建并运行。我的项目没有。

我的项目在 Maven 下构建,但没有运行测试。所以这可能是 Maven 或项目配置问题,与 VSCODE 无关。

我已经尝试了几个小时的各种想法,但没有成功。有些东西不同了,可能是一个错误,也许更多的眼睛可以发现它。我们将非常感谢您提供的任何帮助。

这是一些项目信息

“mvn clean package”运行没有错误,但没有运行测试。 CodeLens 也无法工作。

缺少

运行测试|调试测试。测试运行程序中没有显示任何测试。

这是我的 POM 文件,做了一些修改:

  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.redacted</groupId>
<artifactId>redacted</artifactId>
<packaging>jar</packaging>
<version>0.1.1</version>
<name>redacted</name>

<properties>
<skipTests>false</skipTests>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>

<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- <skipTests>${skipTests}</skipTests> -->
</configuration>
</plugin>
<!-- <plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin> -->
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.3.6</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/WSDL/redacted.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

这是 mvn 命令的输出:

[INFO] 
[INFO] ------------------------< com.redacted:redactedClient >-------------------------
[INFO] Building redactedClient 0.1.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ redactedClient ---
[INFO] Deleting D:\repos\redacted\redactedClient\target
[INFO]
[INFO] --- cxf-codegen-plugin:3.3.6:wsdl2java (generate-sources) @ redactedClient ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to D:\repos\redacted\redactedClient\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ redactedClient ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\repos\redacted\redactedClient\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ redactedClient ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\repos\redacted\redactedClient\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ redactedClient ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.444 s
[INFO] Finished at: 2020-04-26T09:55:55-07:00
[INFO] ------------------------------------------------------------------------

最佳答案

测试方法应具有返回类型 void,而测试方法 GetModList() 具有 Boolean

在 JUnit Jupiter 中,您可以从测试类以及所有测试方法中删除 public。

关于java - JUnit 5 测试未触发并且测试未显示在测试运行程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61445410/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com