簡體   English   中英

無法使用 Surefire 執行特定的嵌套測試 class

[英]Unable to execute specific nested test class with Surefire

我對 Surefire 插件有一點小問題。

我有一個嵌套測試 class 層次結構:

public class NestClassContainer {

    public static class TestClass1 {
        @Test
        public void testC1_m1() {

        }
    }


    public static class TestClass2 {
        @Test
        public void testC2_m1() {

        }
    }

}

我的目標是僅在其中一個嵌套類中執行方法。 不幸的是,我無法具體說明surefire(例如:僅執行testC2_m1() ),盡管這在 TestNG 和 IntelliJ 中都很容易實現。

我努力了:

mvn clean test -Dtest=NestClassContainer$TestClass2

甚至:

mvn clean test -Dtest=com.adobe.campaign.tests.integro.phased.NestClassContainer$TestClass2

我什至嘗試在 surefire 配置中刪除默認排除項。

一般信息:

  • Testng 7.5
  • Maven 3.8.6
  • Surefire:2.19.1、2.22.1、3.0.0-M1
  • java 1.8.0_341 JDK

我認為這只是 shell escaping 問題 - 你是在 *nix 機器上(而不是 Windows)嗎? 如果是這樣,您需要轉義$ ,因為它標志着變量名的開始。

我試過你的例子,它工作正常:

mvn test -Dtest=NestClassContainer\$TestClass1

或者,您可以將整個術語放在單引號中,這會禁用變量插值:

mvn test -Dtest='NestClassContainer$TestClass1'

兩種方法都表明只運行指定的嵌套測試:

===== Invoked methods
    NestClassContainer$TestClass1.testC1_m1()[pri:0, instance:so73579735.NestClassContainer$TestClass1@6cc7b4de]
=====
[TestNG]
[TestNG] ===============================================
[TestNG]     Surefire test
[TestNG]     Tests run: 1, Failures: 0, Skips: []
[TestNG] ===============================================
PASSED: so73579735.NestClassContainer$TestClass1.testC1_m1

===============================================
    Surefire test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Surefire suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

(對於這個 output,必須將 Surefire 配置為在詳細模式下運行 testng)

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M1</version> 
            <configuration>
                <properties>
                    <property>
                        <name>surefire.testng.verbose</name>
                        <value>10</value>
                    </property>
                </properties>
            </configuration>
        </plugin>
    </plugins>
  </build>

在 Windows 上,它與普通的$一起使用,因為該字符在那里沒有特殊含義。

暫無
暫無

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

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