diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 71cb91f2..e29341a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,14 +21,15 @@ jobs: name: "Build" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.0.2 + - uses: actions/checkout@v3.5.3 - name: 'Setup .NET Core SDK' - uses: actions/setup-dotnet@v2.1.0 + uses: actions/setup-dotnet@v3.2.0 with: dotnet-version: | 3.1.x 6.0.x + 7.0.x - name: 'Restore packages' run: dotnet restore ${{ env.SOLUTION_PATH }} --packages ${{ env.RESTORE_OUTPUT_PATH }} @@ -38,5 +39,5 @@ jobs: - name: 'Run tests' run: | - dotnet test Allure.Net.Commons.Tests/Allure.Net.Commons.Tests.csproj --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} - dotnet test Allure.SpecFlowPlugin.Tests/Allure.SpecFlowPlugin.Tests.csproj --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} + dotnet test Allure.Net.Commons.Tests/Allure.Net.Commons.Tests.csproj --no-build --configuration ${{ env.BUILD_CONFIGURATION }} + dotnet test Allure.SpecFlowPlugin.Tests/Allure.SpecFlowPlugin.Tests.csproj --no-build --configuration ${{ env.BUILD_CONFIGURATION }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 37e4f8b6..6d45885a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,23 +14,30 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.0.2 + - uses: actions/checkout@v3.5.3 - name: 'Setup .NET Core SDK' - uses: actions/setup-dotnet@v2.1.0 + uses: actions/setup-dotnet@v3.2.0 with: dotnet-version: | 3.1.x 6.0.x + 7.0.x - name: 'Restore packages' run: dotnet restore ${{ env.SOLUTION_PATH }} --packages ${{ env.RESTORE_OUTPUT_PATH }} - name: 'Build project using dotnet' - run: dotnet build ${{ env.SOLUTION_PATH }} --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} + run: dotnet build ${{ env.SOLUTION_PATH }} --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} -p:ContinuousIntegrationBuild=true + + # Lower AspectInjector requirement for users of the packages to workaround #391 (build crash on macOS arm machines) + - name: Reduce AspectInjector requirement to 2.8.1 + run: | + dotnet add Allure.Net.Commons package AspectInjector --version 2.8.1 + dotnet add Allure.XUnit package AspectInjector --version 2.8.1 - name: 'Pack project' - run: dotnet pack ${{ env.SOLUTION_PATH }} --no-restore --no-build --configuration ${{ env.BUILD_CONFIGURATION }} --include-symbols -p:PackageOutputPath=${{ env.PACKAGE_OUTPUT_PATH }} + run: dotnet pack ${{ env.SOLUTION_PATH }} --no-restore --no-build --configuration ${{ env.BUILD_CONFIGURATION }} -p:PackageOutputPath=${{ env.PACKAGE_OUTPUT_PATH }} - name: 'NuGet publish' run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adab4ba5..9ace6b8b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,14 +45,28 @@ jobs: git config --global user.email qameta-ci@qameta.io - name: "Set release version" run: | - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ env.release_version }}|g' ./Allure.Net.Commons/Allure.Net.Commons.csproj - cat ./Allure.Net.Commons/Allure.Net.Commons.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ env.release_version }}|g' ./Allure.SpecFlowPlugin/Allure.SpecFlowPlugin.csproj - cat ./Allure.SpecFlowPlugin/Allure.SpecFlowPlugin.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ env.release_version }}|g' ./Allure.XUnit/Allure.XUnit.csproj - cat ./Allure.XUnit/Allure.XUnit.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ env.release_version }}|g' ./Allure.NUnit/Allure.NUnit.csproj - cat ./Allure.NUnit/Allure.NUnit.csproj + sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ env.release_version }}|g' ./Directory.Build.props + cat ./Directory.Build.props + - name: "Update schema links" + run: | + sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit/Schemas/allureConfig.schema.json + cat ./Allure.NUnit/Schemas/allureConfig.schema.json + sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.XUnit/Schemas/allureConfig.schema.json + cat ./Allure.XUnit/Schemas/allureConfig.schema.json + sed -i -e '/"$ref"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json + cat ./Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit/allureConfig.json + cat ./Allure.NUnit/allureConfig.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.NUnit.Examples/allureConfig.json + cat ./Allure.NUnit.Examples/allureConfig.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.XUnit.Examples/allureConfig.json + cat ./Allure.XUnit.Examples/allureConfig.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin/allureConfig.Template.json + cat ./Allure.SpecFlowPlugin/allureConfig.Template.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.Features/allureConfig.json + cat ./Allure.Features/allureConfig.json + sed -i -e '/"$schema"/s|/allure-csharp/[^/]*|/allure-csharp/${{ env.release_version }}|g' ./Allure.SpecFlowPlugin.Tests/allureConfig.json + cat ./Allure.SpecFlowPlugin.Tests/allureConfig.json - name: "Commit release version and create tag" run: | git commit -am "release ${{ env.release_version }}" @@ -60,14 +74,8 @@ jobs: git push origin ${{ env.release_version }} - name: "Set next development version" run: | - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ inputs.nextVersion }}-SNAPSHOT|g' ./Allure.Net.Commons/Allure.Net.Commons.csproj - cat ./Allure.Net.Commons/Allure.Net.Commons.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ inputs.nextVersion }}-SNAPSHOT|g' ./Allure.SpecFlowPlugin/Allure.SpecFlowPlugin.csproj - cat ./Allure.SpecFlowPlugin/Allure.SpecFlowPlugin.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ inputs.nextVersion }}-SNAPSHOT|g' ./Allure.XUnit/Allure.XUnit.csproj - cat ./Allure.XUnit/Allure.XUnit.csproj - sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ inputs.nextVersion }}-SNAPSHOT|g' ./Allure.NUnit/Allure.NUnit.csproj - cat ./Allure.NUnit/Allure.NUnit.csproj + sed -i -e '//,/<\/PropertyGroup>/ s|[0-9a-zA-Z.|-]*|${{ inputs.nextVersion }}-SNAPSHOT|g' ./Directory.Build.props + cat ./Directory.Build.props - name: "Commit next development version and push it" run: | git commit -am "set next development version ${{ inputs.nextVersion }}" diff --git a/.gitignore b/.gitignore index cc22f2c1..c8ea7b1f 100644 --- a/.gitignore +++ b/.gitignore @@ -265,3 +265,5 @@ __pycache__/ .DS_Store *mono_crash* /.vscode + +.editorconfig diff --git a/Allure.Features/Allure.Features.csproj b/Allure.Features/Allure.Features.csproj index b994f545..72392200 100644 --- a/Allure.Features/Allure.Features.csproj +++ b/Allure.Features/Allure.Features.csproj @@ -1,32 +1,34 @@  - - netcoreapp3.1 - false - bin - + + netcoreapp3.1 + bin + - - - - - - - - - - - - - - - - - Always - - - - - PreserveNewest - - + + + + + + + + + + + + + + + + + + + + Always + + + + + PreserveNewest + + diff --git a/Allure.Features/TestData/After Feature Failure.feature b/Allure.Features/TestData/After Feature Failure.feature index d7aa18ad..33ef1299 100644 --- a/Allure.Features/TestData/After Feature Failure.feature +++ b/Allure.Features/TestData/After Feature Failure.feature @@ -5,7 +5,7 @@ Feature: After Feature Failure Scenario: After Feature Failure 1 Given Step is 'passed' - @broken + @failed Scenario: After Feature Failure 3 Given Step is 'failed' diff --git a/Allure.Features/TestData/Before Feature Failure.feature b/Allure.Features/TestData/Before Feature Failure.feature index e1159e4a..465ea4c4 100644 --- a/Allure.Features/TestData/Before Feature Failure.feature +++ b/Allure.Features/TestData/Before Feature Failure.feature @@ -2,4 +2,4 @@ Feature: Before Feature Failure @broken - Scenario: Unknown \ No newline at end of file + Scenario: Feature hook failure placeholder \ No newline at end of file diff --git a/Allure.Features/TestData/Invalid Steps.feature b/Allure.Features/TestData/Invalid Steps.feature index 9ad1dfa0..c94b65c6 100644 --- a/Allure.Features/TestData/Invalid Steps.feature +++ b/Allure.Features/TestData/Invalid Steps.feature @@ -12,7 +12,7 @@ Given Step is 'passed' And I don't have such step too - @broken + @failed Scenario: Failed step followed by invalid step Given Step is 'failed' Given I don't have such step diff --git a/Allure.Features/allureConfig.json b/Allure.Features/allureConfig.json index 7af5ca41..1d8ab581 100644 --- a/Allure.Features/allureConfig.json +++ b/Allure.Features/allureConfig.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/identifiers-fix/Allure.SpecFlowPlugin/Schemas/allureConfig.schema.json", "allure": { "title": "5994A3F7-AF84-46AD-9393-000BB45553CC", "directory": "allure-results", diff --git a/Allure.NUnit.Examples/Allure.NUnit.Examples.csproj b/Allure.NUnit.Examples/Allure.NUnit.Examples.csproj index 04b8b914..c50bd13d 100644 --- a/Allure.NUnit.Examples/Allure.NUnit.Examples.csproj +++ b/Allure.NUnit.Examples/Allure.NUnit.Examples.csproj @@ -1,28 +1,28 @@  - - net6.0 - false - Library - + + net6.0 + Library + - - - - + + + + + - - - + + + - - - Always - - - - Always - - + + + Always + + + + Always + + diff --git a/Allure.NUnit.Examples/AllureAsyncOneTimeSetUpTests.cs b/Allure.NUnit.Examples/AllureAsyncOneTimeSetUpTests.cs new file mode 100644 index 00000000..cc9e3e06 --- /dev/null +++ b/Allure.NUnit.Examples/AllureAsyncOneTimeSetUpTests.cs @@ -0,0 +1,44 @@ +using System.Threading.Tasks; +using Allure.NUnit.Examples.CommonSteps; +using NUnit.Allure.Attributes; +using NUnit.Framework; + +namespace Allure.NUnit.Examples +{ + [AllureSuite("Tests - Async OneTime SetUp")] + [Parallelizable(ParallelScope.All)] + public class AllureAsyncOneTimeSetUpTests: BaseTest + { + [OneTimeSetUp] + [AllureBefore] + public async Task OneTimeSetUp() + { + await AsyncStepsExamples.PrepareDough(); + await AsyncStepsExamples.CookPizza(); + await AsyncStepsExamples.CookPizza(); + await AsyncStepsExamples.CookPizza(); + } + + [SetUp] + [AllureBefore] + public async Task SetUp() + { + await AsyncStepsExamples.PrepareDough(); + } + + [Test] + [AllureName("Test1")] + public async Task Test1() + { + await AsyncStepsExamples.DeliverPizza(); + await AsyncStepsExamples.Pay(); + } + + [Test] + [AllureName("Test2")] + public async Task Test2() + { + await AsyncStepsExamples.DeliverPizza(); + } + } +} \ No newline at end of file diff --git a/Allure.NUnit.Examples/AllureAsyncStepTest.cs b/Allure.NUnit.Examples/AllureAsyncStepTest.cs new file mode 100644 index 00000000..48c03c09 --- /dev/null +++ b/Allure.NUnit.Examples/AllureAsyncStepTest.cs @@ -0,0 +1,35 @@ +using System.Threading.Tasks; +using Allure.NUnit.Examples.CommonSteps; +using NUnit.Allure.Attributes; +using NUnit.Framework; + +namespace Allure.NUnit.Examples; + +[AllureSuite("Tests - Async Steps")] +public class AllureAsyncStepTest : BaseTest +{ + private bool _isStep1Finished; + + [Test] + [AllureName("Simple test with async steps")] + public async Task CookPizzaStepByStepTest() + { + await AsyncStepsExamples.PrepareDough(); + await AsyncStepsExamples.CookPizza(); + } + + [Test] + public async Task AwaitingStepsTaskCastTest() + { + await Step1(); + Assert.That(_isStep1Finished, Is.True); + } + + [AllureStep("Step1")] + public async Task Step1() + { + _isStep1Finished = false; + await Task.Delay(500); + _isStep1Finished = true; + } +} diff --git a/Allure.NUnit.Examples/AllureAttachmentsTest.cs b/Allure.NUnit.Examples/AllureAttachmentsTest.cs index 173f604b..9feb69d3 100644 --- a/Allure.NUnit.Examples/AllureAttachmentsTest.cs +++ b/Allure.NUnit.Examples/AllureAttachmentsTest.cs @@ -1,6 +1,6 @@ using System; using System.IO; -using Allure.Net.Commons; +using NUnit.Allure; using NUnit.Allure.Attributes; using NUnit.Framework; @@ -15,10 +15,7 @@ public void AttachmentSimpleTest() Console.WriteLine("With Attachment"); Console.WriteLine(DateTime.Now); - - AllureLifecycle.Instance.AddAttachment( - Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json"), - "AllureConfig.json"); + Attachments.File("AllureConfig.json", Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json")); } } } \ No newline at end of file diff --git a/Allure.NUnit.Examples/AllureSetUpFixture.cs b/Allure.NUnit.Examples/AllureSetUpFixture.cs new file mode 100644 index 00000000..08b224bd --- /dev/null +++ b/Allure.NUnit.Examples/AllureSetUpFixture.cs @@ -0,0 +1,17 @@ +using Allure.Net.Commons; +using NUnit.Allure.Core; +using NUnit.Framework; + +namespace Allure.NUnit.Examples +{ + [SetUpFixture] + public class AllureSetUpFixture + { + [OneTimeSetUp] + public static void CleanupResultDirectory() => + AllureExtensions.WrapSetUpTearDownParams( + AllureLifecycle.Instance.CleanupResultDirectory, + "Clear Allure Results Directory" + ); + } +} diff --git a/Allure.NUnit.Examples/AllureSetUpTearDownTest.cs b/Allure.NUnit.Examples/AllureSetUpTearDownTest.cs index cb8149de..739f7bcb 100644 --- a/Allure.NUnit.Examples/AllureSetUpTearDownTest.cs +++ b/Allure.NUnit.Examples/AllureSetUpTearDownTest.cs @@ -1,5 +1,6 @@ using System; -using System.Threading; +using System.IO; +using NUnit.Allure; using NUnit.Allure.Attributes; using NUnit.Allure.Core; using NUnit.Framework; @@ -10,38 +11,49 @@ namespace Allure.NUnit.Examples public class AllureSetUpTearDownTest : BaseTest { [SetUp] + [AllureBefore("AllureBefore attribute description")] public void SetUp() { Console.WriteLine("I'm an unwrapped SetUp"); + StepsHelper.UpdateTestResult(tr => + { + tr.name = "Some awesome name"; + }); + Attachments.File("AllureConfig.json", Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json")); + StepsExamples.Step1(); } [TearDown] + [AllureAfter("AllureAfter attribute description")] public void TearDown() { - AllureExtensions.WrapSetUpTearDownParams(() => + StepsExamples.Step3(); + StepsHelper.UpdateTestResult(tr => { - Thread.Sleep(750); - Console.WriteLine("Example of wrapped TearDown"); - }, "Custom TearDown name here"); + tr.name = "Some awesome name (changed on teardown)"; + }); + Attachments.File("AllureConfig.json", Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json")); } - [OneTimeSetUp] + [AllureBefore("OneTimeSetUp AllureBefore attribute description")] public void OneTimeSetUp() { Console.WriteLine("I'm an unwrapped OneTimeSetUp"); } [OneTimeTearDown] + [AllureAfter("OneTimeTearDown AllureAfter attribute description")] public void OneTimeTearDown() { Console.WriteLine("I'm an unwrapped OneTimeTearDown"); } [Test] - [AllureSubSuite("Test")] + [AllureSubSuite("Test Subsuite")] public void Test() { + StepsExamples.StepWithParams("first", "second"); } } } \ No newline at end of file diff --git a/Allure.NUnit.Examples/AllureStepLogTests.cs b/Allure.NUnit.Examples/AllureStepLogTests.cs new file mode 100644 index 00000000..51009e56 --- /dev/null +++ b/Allure.NUnit.Examples/AllureStepLogTests.cs @@ -0,0 +1,76 @@ +using System; +using Allure.Net.Commons.Steps; +using NUnit.Allure.Attributes; +using NUnit.Allure.Core; +using NUnit.Framework; +using NUnit.Framework.Internal; + +namespace Allure.NUnit.Examples +{ + class StepActionLogger : IStepActionLogger + { + private readonly string _prefix; + + public StepActionLogger(string prefix) + { + _prefix = prefix; + } + + public void Log(string name) + { + Console.WriteLine(_prefix + ": " + name); + } + } + + class StepActionLoggerNoName : IStepActionLogger + { + private readonly string _message; + + public StepActionLoggerNoName(string message) + { + _message = message; + } + + public void Log(string name) + { + Console.WriteLine(_message); + } + } + + class StepsLogger : IStepLogger + { + public IStepActionLogger StepStarted { get; set; } = new StepActionLogger("Started Step"); + public IStepActionLogger StepPassed { get; set; } = new StepActionLoggerNoName("Passed"); + public IStepActionLogger StepFailed { get; set; } = new StepActionLoggerNoName("Failed"); + public IStepActionLogger StepBroken { get; set; } = new StepActionLoggerNoName("Broken"); + public IStepActionLogger BeforeStarted { get; set; } = null; + public IStepActionLogger AfterStarted { get; set; } = null; + } + + [AllureSuite("Tests - Step Logs")] + public class AllureStepLogTests : BaseTest + { + [OneTimeSetUp] + public void SetStepLogger() + { + StepsHelper.StepLogger = new StepsLogger(); + } + + [Test] + public void LoggerTest() + { + SomeAction(); + + var testOutput = TestExecutionContext.CurrentContext.CurrentResult.Output; + + Assert.That(testOutput, Does.Contain("Started Step: Some action")); + Assert.That(testOutput, Does.Contain("Passed")); + } + + [AllureStep("Some action")] + public void SomeAction() + { + Console.WriteLine("Executing step action"); + } + } +} \ No newline at end of file diff --git a/Allure.NUnit.Examples/AllureStepNameInternalsTest.cs b/Allure.NUnit.Examples/AllureStepNameInternalsTest.cs new file mode 100644 index 00000000..e4710651 --- /dev/null +++ b/Allure.NUnit.Examples/AllureStepNameInternalsTest.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Allure.Net.Commons; +using Allure.Net.Commons.Steps; +using NUnit.Allure.Attributes; +using NUnit.Framework; + +namespace Allure.NUnit.Examples +{ + [AllureSuite("Tests - Step Names")] + public class AllureStepNameInternalsTest : BaseTest + { + internal class LocalTestClass + { + public string TestField; + public string TestProp { get; set; } + + public void TestMethod(string name, LocalTestClass request, int id) + { + Console.WriteLine($"{id} - {name} ({request})"); + } + } + + [TestCase("", ExpectedResult = "")] + [TestCase(null, ExpectedResult = "")] + [TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "\"Super Mario\" - {\"TestField\":\"FieldValue\",\"TestProp\":\"PropValue\"} - 12345 - {3} - {100} - {-100}")] + [TestCase("{id} - {0}", ExpectedResult = "12345 - \"Super Mario\"")] + [TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - \"Super Mario\" ({\"TestField\":\"FieldValue\",\"TestProp\":\"PropValue\"})")] + [TestCase("{id} - {request.TestField} - {request.TestProp}", ExpectedResult = "12345 - \"FieldValue\" - \"PropValue\"")] + [TestCase("{notExistingParameter} - {request.NotExistingField}", ExpectedResult = "{notExistingParameter} - {request.NotExistingField}")] + public string ApplyValues_Test(string stepNamePattern) + { + MethodBase methodBase = typeof(LocalTestClass).GetMethod(nameof(LocalTestClass.TestMethod))!; + object[] arguments = new object[] + { + "Super Mario", // name = {0} + new LocalTestClass // request = {1} + { + TestField = "FieldValue", + TestProp = "PropValue", + }, + 12345, // id = {2} + }; + + return AllureStepParameterHelper.GetStepName( + stepNamePattern, + methodBase, + arguments, + new Dictionary() + ); + } + + [TestCase("", ExpectedResult = "")] + [TestCase(null, ExpectedResult = "")] + [TestCase("{0} - {1} - {2} - {3} - {100} - {-100}", ExpectedResult = "\"Super Mario\" - null - 12345 - {3} - {100} - {-100}")] + [TestCase("{id} - {0}", ExpectedResult = "12345 - \"Super Mario\"")] + [TestCase("{id} - {name} ({request})", ExpectedResult = "12345 - \"Super Mario\" (null)")] + [TestCase("{id} - {request.TestField} - {request.TestProp}", ExpectedResult = "12345 - {request.TestField} - {request.TestProp}")] + [TestCase("{notExistingParameter} - {request.NotExistingField}", ExpectedResult = "{notExistingParameter} - {request.NotExistingField}")] + public string ApplyNullValues_Test(string stepNamePattern) + { + MethodBase methodBase = typeof(LocalTestClass).GetMethod(nameof(LocalTestClass.TestMethod))!; + object[] arguments = new object[] + { + "Super Mario", // name = {0} + null, + 12345, // id = {2} + }; + + return AllureStepParameterHelper.GetStepName( + stepNamePattern, + methodBase, + arguments, + new Dictionary() + ); + } + } +} diff --git a/Allure.NUnit.Examples/BaseTest.cs b/Allure.NUnit.Examples/BaseTest.cs index 0687207d..e7e27a91 100644 --- a/Allure.NUnit.Examples/BaseTest.cs +++ b/Allure.NUnit.Examples/BaseTest.cs @@ -1,7 +1,5 @@ -using Allure.Net.Commons; -using NUnit.Allure.Attributes; +using NUnit.Allure.Attributes; using NUnit.Allure.Core; -using NUnit.Framework; namespace Allure.NUnit.Examples { @@ -9,11 +7,5 @@ namespace Allure.NUnit.Examples [AllureParentSuite("Root Suite")] public class BaseTest { - [OneTimeSetUp] - public void CleanupResultDirectory() - { - AllureExtensions.WrapSetUpTearDownParams(() => { AllureLifecycle.Instance.CleanupResultDirectory(); }, - "Clear Allure Results Directory"); - } } } \ No newline at end of file diff --git a/Allure.NUnit.Examples/CommonSteps/AsyncStepsExamples.cs b/Allure.NUnit.Examples/CommonSteps/AsyncStepsExamples.cs new file mode 100644 index 00000000..e8ac23dd --- /dev/null +++ b/Allure.NUnit.Examples/CommonSteps/AsyncStepsExamples.cs @@ -0,0 +1,40 @@ +using System; +using System.Threading.Tasks; +using NUnit.Allure.Attributes; + +namespace Allure.NUnit.Examples.CommonSteps; + +public static class AsyncStepsExamples +{ + private static readonly Random Random = new(); + + [AllureStep("Prepare dough")] + public static async Task PrepareDough() + { + await AsyncMethod($"Step {nameof(PrepareDough)}"); + } + + [AllureStep("Cook pizza")] + public static async Task CookPizza() + { + await AsyncMethod($"Step {nameof(CookPizza)}"); + } + + [AllureStep("Deliver")] + public static async Task DeliverPizza() + { + await AsyncMethod($"Step {nameof(DeliverPizza)}"); + } + + [AllureStep("Pay")] + public static async Task Pay() + { + await AsyncMethod($"Step {nameof(Pay)}"); + } + private static async Task AsyncMethod(string message) + { + var delay = Random.Next(50, 200); + await Task.Delay(delay); + Console.WriteLine($"{message}"); + } +} \ No newline at end of file diff --git a/Allure.NUnit.Examples/OutputTest.cs b/Allure.NUnit.Examples/OutputTest.cs new file mode 100644 index 00000000..d2d467a0 --- /dev/null +++ b/Allure.NUnit.Examples/OutputTest.cs @@ -0,0 +1,33 @@ +using System; +using System.IO; +using System.Linq; +using Allure.Net.Commons; +using NUnit.Allure.Attributes; +using NUnit.Framework; + +namespace Allure.NUnit.Examples +{ + [AllureSuite("Tests - Output")] + public class OutputTest : BaseTest + { + private const string text = "This should go to console output attachment"; + + [Test] + [Order(1)] + public void WriteOutputTest() + { + Console.WriteLine(text); + } + + [Test] + [Order(2)] + public void OutputLogShouldExist() + { + var resultsDir = AllureLifecycle.Instance.ResultsDirectory; + var attachmentFiles = Directory.EnumerateFiles(resultsDir, "*.txt"); + + Assert.That(attachmentFiles.Any(file => File.ReadAllText(file).Contains(text))); + } + } +} + diff --git a/Allure.NUnit.Examples/allureConfig.json b/Allure.NUnit.Examples/allureConfig.json index 7c59a8f0..f9a5643e 100644 --- a/Allure.NUnit.Examples/allureConfig.json +++ b/Allure.NUnit.Examples/allureConfig.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/allure-framework/allure-csharp/identifiers-fix/Allure.NUnit/Schemas/allureConfig.schema.json", "allure": { "directory": "allure-results", "links": [ diff --git a/Allure.NUnit/Allure.NUnit.csproj b/Allure.NUnit/Allure.NUnit.csproj index a6b089c5..f91b90aa 100644 --- a/Allure.NUnit/Allure.NUnit.csproj +++ b/Allure.NUnit/Allure.NUnit.csproj @@ -2,44 +2,38 @@ netstandard2.0 - 2.10-SNAPSHOT - false - Qameta Software + true Nick Chursin NUnit attributes extenstions for Allure Allure.NUnit Allure.NUnit NUnit.Allure https://www.nuget.org/packages/Allure.NUnit - https://github.com/allure-framework/allure-csharp allure nunit LICENSE.md README.md Allure-N-Color.png - true - snupkg - + + - - - - - - + + + + Always - - - + + + diff --git a/Allure.NUnit/Attachments.cs b/Allure.NUnit/Attachments.cs new file mode 100644 index 00000000..5b93d30c --- /dev/null +++ b/Allure.NUnit/Attachments.cs @@ -0,0 +1,14 @@ +using System.Text; +using Allure.Net.Commons; +using HeyRed.Mime; + +namespace NUnit.Allure +{ + public abstract class Attachments + { + public static void Text(string name, string content) => Bytes(name, Encoding.UTF8.GetBytes(content), ".txt"); + public static void Bytes(string name, byte[] content, string extension = "") => AllureLifecycle.Instance.AddAttachment(name, MimeTypesMap.GetMimeType(extension), content, extension); + public static void File(string name, string path) => AllureLifecycle.Instance.AddAttachment(path, name); + public static void File(string fileName) => File(fileName, fileName); + } +} \ No newline at end of file diff --git a/Allure.NUnit/Attributes/AllureAfterAttribute.cs b/Allure.NUnit/Attributes/AllureAfterAttribute.cs new file mode 100644 index 00000000..2d6dfd5e --- /dev/null +++ b/Allure.NUnit/Attributes/AllureAfterAttribute.cs @@ -0,0 +1,14 @@ +using Allure.Net.Commons.Steps; +using AspectInjector.Broker; +using NUnit.Allure.Core; + +namespace NUnit.Allure.Attributes +{ + [Injection(typeof(Internals.StopContainerAspect), Inherited = true)] + public class AllureAfterAttribute : AllureStepAttributes.AbstractAfterAttribute + { + public AllureAfterAttribute(string name = null) : base(name, AllureNUnitHelper.ExceptionTypes) + { + } + } +} \ No newline at end of file diff --git a/Allure.NUnit/Attributes/AllureBeforeAttribute.cs b/Allure.NUnit/Attributes/AllureBeforeAttribute.cs new file mode 100644 index 00000000..d7fbc918 --- /dev/null +++ b/Allure.NUnit/Attributes/AllureBeforeAttribute.cs @@ -0,0 +1,12 @@ +using Allure.Net.Commons.Steps; +using NUnit.Allure.Core; + +namespace NUnit.Allure.Attributes +{ + public class AllureBeforeAttribute : AllureStepAttributes.AbstractBeforeAttribute + { + public AllureBeforeAttribute(string name = null) : base(name, AllureNUnitHelper.ExceptionTypes) + { + } + } +} \ No newline at end of file diff --git a/Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs b/Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs index ebf5d5b1..be81344f 100644 --- a/Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs +++ b/Allure.NUnit/Attributes/AllureDisplayIgnoredAttribute.cs @@ -1,20 +1,27 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using Allure.Net.Commons; +using NUnit.Allure.Core; using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using TestResult = Allure.Net.Commons.TestResult; +#nullable enable + namespace NUnit.Allure.Attributes { [AttributeUsage(AttributeTargets.Class)] public class AllureDisplayIgnoredAttribute : NUnitAttribute, ITestAction { - private readonly string _suiteName; - private string _ignoredContainerId; + private readonly string? _suiteName = null; + + public AllureDisplayIgnoredAttribute(){} + [Obsolete("Allure attributes are now supported for ignored tests. Use them instead")] + [EditorBrowsable(EditorBrowsableState.Never)] public AllureDisplayIgnoredAttribute(string suiteNameForIgnoredTests = "Ignored") { _suiteName = suiteNameForIgnoredTests; @@ -22,13 +29,11 @@ public AllureDisplayIgnoredAttribute(string suiteNameForIgnoredTests = "Ignored" public void BeforeTest(ITest suite) { - _ignoredContainerId = suite.Id + "-ignored"; - var fixture = new TestResultContainer + AllureLifecycle.Instance.StartTestContainer(new() { - uuid = _ignoredContainerId, + uuid = suite.Id + "-ignored", name = suite.ClassName - }; - AllureLifecycle.Instance.StartTestContainer(fixture); + }); } public void AfterTest(ITest suite) @@ -37,41 +42,17 @@ public void AfterTest(ITest suite) if (suite.HasChildren) { var ignoredTests = - GetAllTests(suite).Where(t => t.RunState == RunState.Ignored || t.RunState == RunState.Skipped); + GetAllTests(suite).Where( + t => t.RunState == RunState.Ignored + || t.RunState == RunState.Skipped + ); foreach (var test in ignoredTests) { - AllureLifecycle.Instance.UpdateTestContainer(_ignoredContainerId, t => t.children.Add(test.Id)); - - var reason = test.Properties.Get(PropertyNames.SkipReason).ToString(); - - var ignoredTestResult = new TestResult - { - uuid = test.Id, - name = test.Name, - fullName = test.FullName, - status = Status.skipped, - statusDetails = new StatusDetails - { - message = test.Name - }, - labels = new List