There multiple possibilities, each coming with its own advantages and inconvenients.
Pickles supports xUnit, NUnit, and cucumber-json reports, among others. So I need to find a way to get a report from behave in one of those formats. xUnit and NUnit are .NET-specific formats, so they have no relation with python. Behave supports, however, json output. Unfortunately, behave's json output is not the cucumber-json format pickles expects.
Convert JUnit test reports into NUnit reports through an XSLT transformation
Of course, behave supports JUnit and it's possible to convert the JUnit test to NUnit through an XSLT transformation. According to this post, there is a (possibly outdated) XSLT transformation here. Such a transformation can be carried out with Apache Ant, which is great, because I am working on TeamCity which comes with a build type of that kind. In Kotlin DSL, this means I could update my build step with something like
steps {
[whatever script steps or other stuff]
ant {
mode = antScript {
content = """
<target name="transform" description="Run functional tests">
<xslt in="${'
The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.
If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.
And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:
# run_behave.py
import os
from behave.configuration import Configuration
from behave.formatter import _registry
from behave.runner import Runner
from my_formatter_package import PrettyCucumberJSONFormatter
here = os.path.dirname(os.path.abspath(__file__))
_registry.register_as("PrettyCucumberJSONFormatter", PrettyCucumberJSONFormatter)
configuration = Configuration(junit_directory="behave_reports")
configuration.format = ["PrettyCucumberJSONFormatter"]
configuration.stdout_capture = False
configuration.stderr_capture = False
configuration.paths = [os.path.join(here, "features")]
Runner(configuration).run()
And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.
}{PATH_TO_THE_JUNIT_FILE}" out="${'
The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.
The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as
If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.
copy / paste the code into file venv/Lib/site-packages/behave/formatter/cucumber_json.py
run
And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:
And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.
The problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.
The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as
If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my Background steps were flagged as skipped in my cucumber-report.json output, making that solution a no-go, because it doesn't show the right status of my scenarios.
copy / paste the code into file venv/Lib/site-packages/behave/formatter/cucumber_json.py
run
And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:
And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to behave.
发布评论
评论(1)
有多种可能性,每种都有自己的优势和不便。
Pickles支持Xunit,Nunit和Cucumber-Json报告等。因此,我需要找到一种方法,以其中一种形式的方式来获取报告。 Xunit和Nunit是.NET特定格式,因此它们与Python没有关系。但是,行为支持JSON输出。不幸的是,Beht的JSON输出不是Cucumber-Json格式腌制的期望。
通过XSLT转换,将JUNIT测试报告转换为Nunit报告
,
行为
支持Junit
,并且可以通过XSLT转换将Junit Test转换为Nunit。根据这篇文章,有一个(可能过时的)XSLT变换在这里。可以使用Apache Ant进行这样的转换,这很棒,因为我正在使用这种构建类型的团队合作。在Kotlin DSL中,这意味着我可以使用该方法的问题更新我的构建步骤,即如果我想测试这样的脚本,我需要在开发PC上安装很多Java东西,并且我不太喜欢爪哇东西。除此之外,还有此NPM软件包这可能会有所帮助。它没有很多星星,但可能会很好。总而言之,我对XSLT不太满意,因此我不喜欢这种解决方案。
使用 behave2cumber2cumber
包装名称听起来很棒,并且使用它似乎很容易。因此,这是我首选的解决方案。就像奏效的那样简单
,我会很高兴,因为从本质上讲,PYPI的所有内容都可以从中获得,听起来真的很棒。但是,我所有的
背景
步骤都标记为在我的
没有显示我方案的正确状态。cucumber-report.json
输出中跳过写下我自己的自定义格式化器
以下这个github问题,我偶然发现了一些解释 和some code (相同的代码)。 Here are the steps it took me to make it work:
,并且可以像魅力一样工作。因为我在许多项目中都需要这个格式化器,所以我的下一步将是生产一个可以在这些项目中安装的Python软件包并参考类似的内容:
这应该可以解决问题。这种方法的不便是我需要维护自己的格式化器。我不知道将来将在JSON输出中改变哪些新的表现版本,以及 cucumber-json架构会随着时间的推移而发展。希望这个格式化将被集成到
行为
。There multiple possibilities, each coming with its own advantages and inconvenients.
Pickles supports xUnit, NUnit, and cucumber-json reports, among others. So I need to find a way to get a report from behave in one of those formats. xUnit and NUnit are .NET-specific formats, so they have no relation with python. Behave supports, however, json output. Unfortunately, behave's json output is not the cucumber-json format pickles expects.
Convert JUnit test reports into NUnit reports through an XSLT transformation
Of course,
behave
supportsJUnit
and it's possible to convert the JUnit test to NUnit through an XSLT transformation. According to this post, there is a (possibly outdated) XSLT transformation here. Such a transformation can be carried out with Apache Ant, which is great, because I am working on TeamCity which comes with a build type of that kind. In Kotlin DSL, this means I could update my build step with something likeThe problem with that approach is that I need to install a lot of Java stuff on my development PC if I want to test such a script and I am not very fond of Java stuff. Other than that, there is this npm package that could help. It has not a lot of stars, but it might work well. To sum up, I am not very comfortable with XSLTs, therefore I don't like this solution.
Use behave2cucumber
The package name sounds really great, and using it seems very easy. So this was a priori my preferred solution. It is as simple as
If that worked, I would've been so happy, because essentially everything is available from pypi, sounds really great. However, all my
Background
steps were flagged asskipped
in mycucumber-report.json
output, making that solution a no-go, because it doesn't show the right status of my scenarios.Write my own custom formatter
Following this github issue, I stumbled upon some explanations and some code (same code here). Here are the steps it took me to make it work:
venv/Lib/site-packages/behave/formatter/cucumber_json.py
And that works like a charm. Because I need this formatter in many projects, my next steps will be to produce a python package that I can install in those projects and reference something like this:
And that should do the trick. The inconvenient of that approach is that I need to maintain my own formatter. I don't know what new behave versions will change in the json output in the future and how the cucumber-json schema will evolve with time. Hopefully this formatter will get integrated to
behave
.