首页 > 解决方案 > Behat、JUnit 和 Jenkins

问题描述

试图将 Behat 结果解释为 JUnit 报告时,我有点发疯了。

我正在使用 ant 构建来生成测试结果,这就是它的调用方式:

<target name="behat" description="Run Behat Scenarios">
    <exec executable="php">
        <arg value="vendor/behat/behat/bin/behat" />
        <arg value="--format" />
        <arg value="pretty" />
        <arg value="--out" />
        <arg value="std" />
        <arg value="--format" />
        <arg value="junit" />
        <arg value="--out" />
        <arg value="${basedir}/build/logs/" />
    </exec>
</target>

这是 Jenkins 的控制台输出:

INFO: Processing JUnit
INFO: [JUnit] - 1 test report file(s) were found with the pattern 'build/logs/default.xml' relative to '/var/lib/jenkins/workspace/Web-Analysis' for the testing framework 'JUnit'.
WARNING: The file '/var/lib/jenkins/workspace/Web-Analysis/build/logs/default.xml' is an invalid file.
WARNING: At line 4 of file:/var/lib/jenkins/workspace/Web-Analysis/build/logs/default.xml:cvc-complex-type.3.2.2: Attribute 'status' is not allowed to appear in element 'testcase'.
WARNING: At line 5 of file:/var/lib/jenkins/workspace/Web-Analysis/build/logs/default.xml:cvc-complex-type.3.2.2: Attribute 'status' is not allowed to appear in element 'testcase'.
ERROR: The plugin hasn't been performed correctly: The result file '/var/lib/jenkins/workspace/Web-Analysis/build/logs/default.xml' for the metric 'JUnit' is not valid. The result file has been skipped.

这是生成的 JUnit 文件:

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="default">
  <testsuite name="Testing" tests="2" skipped="0" failures="0" errors="0" time="0">
    <testcase name="Home Page" status="passed" time="0"></testcase>
    <testcase name="Dashboard is locked to guests" status="passed" time="0"></testcase>
  </testsuite>
</testsuites>

我已经看到了一些与之相关的问题,但无法真正找到有关如何解决此问题的答案。任何帮助将不胜感激,如果需要,我很乐意提供更多详细信息!如果有帮助,我正在使用 Behat 3.5.0。

--edit 只需添加 behat.yml 和控制台输出

default:
    gherkin:
        cache: ~
    extensions:
        Laracasts\Behat\ServiceContainer\BehatExtension: ~
        Behat\MinkExtension\ServiceContainer\MinkExtension:
            default_session: laravel
            laravel: ~



behat:
     [exec] Feature: Testing
     [exec]     In order to learn Behat
     [exec]     As a developer
     [exec]     I want to learn how to install and create features
     [exec] 
     [exec]   Scenario: Home Page                  # features/example.feature:6
     [exec]     Given I am on the homepage         # FeatureContext::iAmOnHomepage()
     [exec]     Then I should see "Audio" # FeatureContext::assertPageContainsText()
     [exec] 
     [exec]   Scenario: Dashboard is locked to guests # features/example.feature:10
     [exec]     When I go to "admin"                  # FeatureContext::visit()
     [exec]     Then the url should match "login"     # FeatureContext::assertUrlRegExp()
     [exec]     And I can do something with Laravel   # FeatureContext::iCanDoSomethingWithLaravel()
     [exec] 
     [exec] 2 scenarios (2 passed)
     [exec] 5 steps (5 passed)
     [exec] 0m0.14s (22.99Mb)

标签: jenkinsjunitbehat

解决方案


在将 Jenkins xUnit 插件升级到 2.2.3(从 2.0.0)后,我遇到了这个问题,降级到 2.0.0“解决了”这个问题。


推荐阅读