【发布时间】:2018-08-20 09:29:25
【问题描述】:
试图将 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。
--编辑 只需添加 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)
【问题讨论】:
-
问题是输出文件根据 JUnit/Jenkins 无效。我的建议是尝试找出它的外观并查看 Behat 的文档以了解如何创建这样的输出。
-
完全以同样的方式理解问题!通过 behat 的 junit 选项生成输出时有点奇怪 - 所以我认为我的生成方式可能存在错误。我尽我所能遵循文档,但找不到答案。目前我最好的选择是使用 xsltproc 重构报告(我什至可能不得不这样做才能使用多个测试套件),但如果我可以避免这一步,我很乐意这样做!