【问题标题】:@DisplayName not working when tests executed through maven当通过 Maven 执行测试时,@DisplayName 不起作用
【发布时间】:2019-05-07 03:39:18
【问题描述】:

通过 maven 执行时,JUnit5 测试结果未显示指定的 @DisplayName。

在 Eclipse 下运行时,相同的测试套件会显示正确分配的名称(右键单击 --> 运行方式... --> JUnit 测试)。

这是已实施测试的示例:

@DisplayName(value="prog QA suite")
public class ProgQATest {

    @Test
    @Tag(value="TestProg")
    @DisplayName(value="prog QA present")
    public void testProg2QaPresent(String searchstring)
    {
        /* test code... */
    }
}

当使用 eclipse 运行时,显示“prog QA suite”和“prog QA present”作为名称。

但是,当使用“maven test”运行时,会显示“ProgQATest”和“testProg2QaPresent”作为名称。

使用的pom.xml是:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.jupiter.version>5.3.2</junit.jupiter.version>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>com.github.pageobject</groupId>
        <artifactId>pageobject-core</artifactId>
        <version>1.0.1</version>
    </dependency>
    <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-params</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>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.0.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M1</version>
            <configuration>
                <forkCount>20</forkCount>
                <reuseForks>false</reuseForks>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
    </plugins>
</build>

非常感谢您的帮助!

【问题讨论】:

标签: maven junit5 junit-jupiter


【解决方案1】:

检查您的 @Test 导入。 当我使用import org.junit.jupiter.api.Test; 时,我的问题已解决 我在使用import org.junit.Test;时遇到了同样的问题

【讨论】:

  • 听起来合乎逻辑 :) 但在我的项目中改变它会导致问题......太糟糕了,在我完全从 JUnit 4 迁移到 JUnit5 之前我不会使用 @DisplayName :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-30
  • 1970-01-01
相关资源
最近更新 更多