簡體   English   中英

JUnit 5 個測試未觸發且測試未在測試運行器中顯示

[英]JUnit 5 tests are not firing and tests aren't showing in test runner

我無法讓 JUnit 5 測試在 VSCODE 上運行。 我相信我的環境設置正確。 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 命令中的 output:

[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 從測試 class 中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM