Skip to content

Commit

Permalink
Reqnroll adapter (#463)
Browse files Browse the repository at this point in the history
* Implement an adapter for Reqnroll (#453)

* Port samples from Allure.Features to Reqnroll

* Write configuration tests for Allure Reqnroll

* Port integration tests of allure-specflow to Reqnroll

* Remove stepAssemblies from README and samples

* Test Allure Reqnroll in build workflow

* Add Allure.Reqnroll entries to README and labeler

* Port test configuration fix from SpecFlow

* Remove IgnoreException from reqnroll samples

* Describe where to find results by default for Reqnroll

* Remove file with unused NUnit attrs
  • Loading branch information
delatrie authored Mar 28, 2024
1 parent fab3267 commit fb4fd65
Show file tree
Hide file tree
Showing 48 changed files with 3,258 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@
- "Allure.SpecFlow/**"
- "Allure.SpecFlow.Tests/**"
- "Allure.SpecFlow.Tests.Samples/**"

"theme:reqnroll":
- changed-files:
- any-glob-to-any-file:
- "Allure.Reqnroll/**"
- "Allure.Reqnroll.Tests/**"
- "Allure.Reqnroll.Tests.Samples/**"
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ jobs:
- name: 'Run tests'
run: |
dotnet test Allure.Net.Commons.Tests/Allure.Net.Commons.Tests.csproj\
dotnet test Allure.Net.Commons.Tests\
--no-build\
--configuration ${{ env.BUILD_CONFIGURATION }}
dotnet test Allure.SpecFlow.Tests/Allure.SpecFlow.Tests.csproj\
dotnet test Allure.SpecFlow.Tests\
--no-build\
--configuration ${{ env.BUILD_CONFIGURATION }}
dotnet test Allure.Reqnroll.Tests\
--no-build\
--configuration ${{ env.BUILD_CONFIGURATION }}
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
cat ./Allure.Xunit/Schemas/allureConfig.schema.json
sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlow/Schemas/allureConfig.schema.json
cat ./Allure.SpecFlow/Schemas/allureConfig.schema.json
sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Reqnroll/Schemas/allureConfig.schema.json
cat ./Allure.Reqnroll/Schemas/allureConfig.schema.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Net.Commons/allureConfig.Template.json
cat ./Allure.Net.Commons/allureConfig.Template.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit.Examples/allureConfig.json
Expand All @@ -67,6 +69,12 @@ jobs:
cat ./Allure.SpecFlow.Tests.Samples/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlow.Tests/allureConfig.json
cat ./Allure.SpecFlow.Tests/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Reqnroll/allureConfig.Template.json
cat ./Allure.Reqnroll/allureConfig.Template.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Reqnroll.Tests.Samples/allureConfig.json
cat ./Allure.Reqnroll.Tests.Samples/allureConfig.json
sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Reqnroll.Tests/allureConfig.json
cat ./Allure.Reqnroll.Tests/allureConfig.json
- name: "Update release notes link"
run: |
sed -i -e '/<PackageReleaseNotes>/,/<\/PackageReleaseNotes>/ s|/allure-csharp/releases/tag/.*\.|/allure-csharp/releases/tag/${{ inputs.nextVersion }}.|g' ./Directory.Build.props
Expand Down
33 changes: 33 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Allure.Reqnroll.Tests.Samples.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>Allure.ReqnrollPlugin.Tests.Samples</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Content Include="allureConfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Reqnroll" Version="1.0.1" />
<PackageReference Include="Reqnroll.Tools.MsBuild.Generation" Version="1.0.1" />
<PackageReference Include="Reqnroll.xUnit" Version="1.0.1" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Allure.Net.Commons\Allure.Net.Commons.csproj" />
<ProjectReference Include="..\Allure.Reqnroll\Allure.Reqnroll.csproj" />
</ItemGroup>

</Project>
114 changes: 114 additions & 0 deletions Allure.Reqnroll.Tests.Samples/BindingDefinitions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Allure.Net.Commons;
using Reqnroll;
using Reqnroll.UnitTestProvider;
using Xunit;

namespace Allure.ReqnrollPlugin.Tests.Samples;
public enum TestOutcome
{
passed,
failed,
broken
}

[Binding]
public class BindingDefinitions
{
readonly ScenarioContext scenarioContext;
readonly IUnitTestRuntimeProvider runnerRuntimeApi;

public BindingDefinitions(ScenarioContext scenarioContext, IUnitTestRuntimeProvider runnerRuntimeApi)
{
this.scenarioContext = scenarioContext;
this.runnerRuntimeApi = runnerRuntimeApi;
}

[BeforeTestRun]
public static void BeforeTestRun() =>
AllureLifecycle.Instance.CleanupResultDirectory();

[StepDefinition(@"Step is '(.*)'")]
public static async Task StepResultIs(TestOutcome outcome)
{
switch (outcome)
{
case TestOutcome.failed:
Assert.Fail("Assertion failed");
break;
case TestOutcome.broken:
throw new Exception("This test was failed");
}
await Task.CompletedTask;
}

[StepDefinition("Step with attachment")]
public static void StepWithAttach() =>
AllureApi.AddAttachment(
"Text attachment",
"text/plain",
"Attachment content"u8.ToArray()
);

[StepDefinition("Step with table")]
public static void StepWithTable(Table _) { }

[StepDefinition("Step with params: (.*)")]
public static void StepWithArgs(int _, string __) { }

[BeforeFeature("beforefeaturepassed", Order = 1)]
public static void PassedBeforeFeature() { }

[AfterFeature("afterfeaturepassed", Order = 1)]
public static void PassedAfterFeature() { }

[BeforeFeature("beforefeaturefailed")]
public static void FailedBeforeFeature() =>
throw new Exception("BeforeFeature failed");

[AfterFeature("afterfeaturefailed")]
public static void FailedAfterFeature() =>
throw new Exception("AfterFeature failed");

[BeforeScenario("beforescenario")]
[AfterScenario("afterscenario")]
[BeforeStep("beforestep")]
[AfterStep("afterstep")]
public void HandleIt() =>
this.Handle(scenarioContext.ScenarioInfo.Tags);

void Handle(string[] tags)
{
if (tags != null && tags.Contains("attachment"))
{
var content = "text file"u8.ToArray();
AllureApi.AddAttachment("attachment-1", "text/plain", content, ".txt");
AllureApi.AddAttachment("attachment-2", "text/plain", content, ".txt");
}

if (tags != null)
{
if (ShouldFail(tags))
{
Assert.Fail("The hook has failed");
}
else if (ShouldBreak(tags))
{
throw new Exception("The hook is broken");
}
else if (tags.Contains("runtimeignore"))
{
this.runnerRuntimeApi.TestIgnore("Ignored because of '@runtimeignore'");
}
}
}

static bool ShouldFail(IEnumerable<string> tags) =>
tags.Any(t => t.EndsWith("failed"));

static bool ShouldBreak(IEnumerable<string> tags) =>
tags.Any(t => t.EndsWith("broken"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@afterfeaturefailed
Feature: After Feature Failure

@passed
Scenario: After Feature Failure 1
Given Step is 'passed'

@failed
Scenario: After Feature Failure 3
Given Step is 'failed'
26 changes: 26 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Attachments.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Attachments

@passed @attachment @beforescenario @afterscenario
Scenario: With attachments
Given Step with attachment
Given Step is 'passed'

@broken @attachment @beforescenario
Scenario: Failed BeforeScenario with attachment
Given Step with attachment
Given Step is 'passed'

@broken @attachment @afterscenario
Scenario: Failed AfterScenario with attachment
Given Step with attachment
Given Step is 'passed'

@broken @attachment @beforestep
Scenario: Failed BeforeStep with attachment
Given Step with attachment
Given Step is 'passed'

@broken @attachment @afterstep
Scenario: Failed AfterStep with attachment
Given Step with attachment
Given Step is 'passed'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@beforefeaturefailed
Feature: Before Feature Failure

@broken
Scenario: BeforeFeature of 'Before Feature Failure' has failed
6 changes: 6 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Ignored.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Ignored
Treat exceptions thrown by IUnitTestRuntimeProvider.TestIgnore as skipped
(works in NUnit and xUnit.net)

@beforescenario @runtimeignore @skipped
Scenario: Should be ignored at runtime
20 changes: 20 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Invalid Steps.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Invalid Steps

@broken
Scenario: All steps are invalid
Given I don't have such step
And I don't have such step too

@broken
Scenario: Some steps are invalid
Given Step is 'passed'
Given I don't have such step
Given Step is 'passed'
And I don't have such step too

@failed
Scenario: Failed step followed by invalid step
Given Step is 'failed'
Given I don't have such step
Given Step is 'passed'
And I don't have such step too
23 changes: 23 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Labels.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@labels @core @epic:v1.2 @owner:JohnDoe
Feature: Labels

@passed @ui @story:accounting @123 @tms:234 @tag1
Scenario: [v1.2 accounting] [ui.core] Selenium test 1

@passed @api @blocker @567 @999999
Scenario: [v1.2] [api.core] Api test 1

@passed @api @create @link:http://example.org
Scenario: [v1.2] [api.core.create] Api test 2

@passed @api @update
Scenario: [v1.2] [api.core.update] Api test 3

@passed @update @story:accounting
Scenario: [v1.2 accounting] [core.update] Update test

@passed @epic:v.2.0 @story:security
Scenario: [v1.2 / v.2.0 security] [core.update] [com.company.security.main.getACL] Get ACL test

@passed @label:layer:e2e @label:allure_id:9894 @label:custom_label:pepa
Scenario: Layer e2e (label)
27 changes: 27 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Scenario Hooks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Feature: Scenario and Step Bindings

@broken @beforescenario @beforestep
Scenario: Should handle BeforeScenario and BeforeStep failure
Given Step is 'passed'
Given Step is 'passed'

@broken @beforescenario
Scenario: Should handle BeforeScenario failure
Given Step is 'passed'
Given Step is 'passed'

@broken @beforestep
Scenario: Should handle BeforeStep failure
Given Step is 'passed'
Given Step is 'passed'
Given Step is 'passed'

@broken @afterstep
Scenario: Should handle AfterStep failure
Given Step is 'passed'
Given Step is 'passed'

@broken @afterscenario
Scenario: Should handle AfterScenario failure
Given Step is 'passed'
Given Step is 'passed'
25 changes: 25 additions & 0 deletions Allure.Reqnroll.Tests.Samples/Features/Scenarios and Steps.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Scenarios and Steps

@passed
Scenario: Empty scenario

@passed
Scenario: Passed scenario
Given Step is 'passed'

@failed
Scenario: Failed scenario
Given Step is 'passed'
Given Step is 'failed'
Given Step is 'passed'

@passed @examples
Scenario Outline: Scenario with examples
Given Step with table
| id | <id> |
| name | <name> |

Examples:
| id | name |
| 1 | John |
| 2 | Alex |
Loading

0 comments on commit fb4fd65

Please sign in to comment.