Allow to output the cucumber.json format
AnsweredHi,
I was wondering if it would be possible to generate a report in a JSON format.
Cucumber allow this, through the -f or -p option.
This is the missing piece in using SpecFlow in a complexe project, publishing results on another tool(XRAY), which links JIRA feature to SpecFlow scenarios.
-
Update: Thanks @matusnovak for sharing a workaround with the community. Follow the steps below:
I am assuming you have the following dependency in your csproj file:
<PackageReference Include="SpecRun.SpecFlow" Version="3.3.41" />
Create a file named
Default.srprofile
right next to your csproj file (maybe a root directory of your project) with the following contents:<?xml version="1.0" encoding="utf-8"?> <TestProfile xmlns="http://www.specflow.org/schemas/plus/TestProfile/1.5"> <Settings projectName="HotelBookingTests" /> <Execution stopAfterFailures="3" testThreadCount="1" testSchedulingMode="Sequential" /> <Report> <Template name="../../../Templates/CucumberJson.cshtml" outputName="Report.json"/> </Report> <TestAssemblyPaths> <TestAssemblyPath>Example.dll</TestAssemblyPath> </TestAssemblyPaths> </TestProfile>
This profile specifies that the report shall be created as
Report.json
with theCucumberJson.cshtml
template.To get the template, download the following package: https://www.nuget.org/packages/SpecRun.Runner/ and extract it as a zip file. No need to install it at all, just open with some zip manager, 7-Zip will do just fine.
The
CucumberJson.cshtml
is in thetemplates
folder within the NuGet package.You will need to create a folder named
Templates
in your project, right next to yourDefault.srprofile
file and put the JSON template in that folder.That's all. After that all I did was to run the tests (In Visual Studio: Test -> Run all tests) and it created the test report as a JSON file. It should also work with .NET Core.
I don't understand why the JSON template is hidden in such way, why not just provide it within SpecFlow documentation? One does not automatically assume that they need to extract the nuget package.
0 -
Great work Mario Steiner. Let me also share a tutorial for Xray on Jira server/DC that exemplifies precisely this. It's a bit old but I think it's in line with what you shared.
0 -
Will this work with .Net 6???
0 -
Thanks @Mario Steiner
But I am getting conflict here, When I create specflow nunit project by default SpecFlow.NUnit is part of csproj
But you are suggestion to add SpecRun.SpecFlow this makes the conflict and getting build error
0 -
I was able to workaround the limitation by using Pickles - the open source Living Documentation Generator (picklesdoc.com)
dotnet pickles --output-directory=/app/TestResults --link-results-file=./TestResults/TestResults.{framework}.{project}.xml --documentation-format=cucumber --test-results-format=xunit2 --excludeTags=ignore
0 -
hi Павел Левчук
could you share a solution?
0 -
Hi Павел Левчук ,is that mean you can generate the JSON report when finish the test using Pickles - the open source Living Documentation Generator (picklesdoc.com)
0
Please sign in to leave a comment.
Comments
7 comments