为什么maven-failsafe-plugin不显示已执行的宁静测试?

时间:2018-09-10 13:04:34

标签: java maven serenity-bdd

我使用Serenity设置了一个基本项目,运行mvn clean verify时出现显示结果的问题

[INFO] --- maven-failsafe-plugin:2.20:integration-test (default) @ functional-tests ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running starter.SmokeTestSuite
Feature: Booking

  @Smoke
  Scenario Outline: Book a reservation # src/test/resources/features/book/booking_creation.feature:4
    Given an agent with role "ADMIN" has logged in

    Examples:

  @Smoke
  Scenario Outline: Book a reservation # src/test/resources/features/book/booking_creation.feature:19
Started InternetExplorerDriver server (32-bit)
3.13.0.0
Listening on port 11642
Only local connections are allowed
Sep 10, 2018 7:50:29 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
    Given an agent with role "ADMIN" has logged in                    # LoginSteps.agent_has_logged_in(String)

1 Scenarios (1 passed)
1 Steps (1 passed)
0m18.568s

[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 19.681 s - in starter.SmokeTestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

这些是我从此问题中得出的一些事实:

  • 未显示“宁静和测试开始”的ASCII艺术,但显示了“测试失败”的ASCII艺术
  • 测试正在运行(如您在日志中看到的,它显示1个通过的场景),问题在于它没有显示已执行的测试数量
  • 测试通过与否并不重要,它仍然不会显示任何内容
  • 赛跑者类是Runner / SmokeTestSuite.java

这是我的pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>functional-tests</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>functional tests</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>1.9.26</serenity.version>
        <serenity.maven.version>1.9.26</serenity.maven.version>
        <serenity.cucumber.version>1.9.8</serenity.cucumber.version>
        <encoding>UTF-8</encoding>
        <tags></tags>
        <parallel.tests>4</parallel.tests>
        <webdriver.base.url></webdriver.base.url>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-junit</artifactId>
            <version>${serenity.version}</version>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-screenplay</artifactId>
            <version>${serenity.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-screenplay-webdriver</artifactId>
            <version>${serenity.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>${serenity.cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>3.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <includes>
                        <include>**/*TestSuite.java</include>
                    </includes>
                    <!-- 
                    <systemPropertyVariables>
                        <webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
                    </systemPropertyVariables>
                     -->
                    <parallel>classes</parallel>
                    <threadCount>${parallel.tests}</threadCount>
                    <forkCount>${parallel.tests}</forkCount>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.maven.version}</version>
                <configuration>
                    <tags>${tags}</tags>
                </configuration>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

感谢您的帮助,谢谢!

2 个答案:

答案 0 :(得分:0)

这不能回答您有关为什么maven-failsafe-plugin不显示已执行测试的问题,但是我有同样的问题,如果测试失败,则需要使构建失败。

运行测试,但不报告执行情况:

Reports view generated with 288 stories (of which 1 pending) containing 2463 scenarios (of which 1 pending)
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 23,875.336 sec

我没有运气就升级了Serenity,JBehave和Selenium依赖项。

我求助于使用serenity-maven-plugin:check目标在验证阶段使构建失败(而不是maven-failsafe-plugin):

<plugin>
    <groupId>net.serenity-bdd.maven.plugins</groupId>
    <artifactId>serenity-maven-plugin</artifactId>
    ...
    <execution>
        <phase>verify</phase>
        <goals>
            <goal>check</goal>
        </goals>
    </execution>

根据要求会导致构建失败:

[INFO] --- serenity-maven-plugin:1.9.45:check (default) @ project-testing ---
[INFO] Checking Serenity test results
[INFO] ----------------------
[INFO] SERENITY TEST OUTCOMES
[INFO] ----------------------
[INFO]   - Tests executed: 2628
[INFO]   - Tests passed: 1823
[INFO]   - Tests failed: 48
[INFO]   - Tests with errors: 757
[INFO]   - Tests pending: 0
[INFO]   - Tests compromised: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.serenity-bdd.maven.plugins:serenity-maven-plugin:1.9.45:check (default) on project project-testing: An error occurred in the Serenity tests -> [Help 1]

答案 1 :(得分:0)

我在一个类似的项目中遇到了同样的问题。 surefire不计算宁静测试结果的原因是因为POM包含JUnit和TestNG工件。通过父POM添加了TestNG工件。

在删除TestNG依赖项之后,报告显示了已执行的测试数量。