Skip to content

Commit 51b6f15

Browse files
authored
Runtime API (#414)
* Move step/fixture runtime API to the Allure facade 1. Step/fixture functions moved from CoreStepsHelper to Allure 2. Unit tests adjusted 3. Add info about Allure to README 4. Adjust examples to use Allure 5. Make CoreStepsHelper and its subclasses obsoleted Related to #404 * Generate xmldoc for commons. Also remove AddParameter from TestResult (discussed). * Move attachment methods to Allure facade Related to #404 * Remove UTF-8 BOM from schemas. * Rename Allure to AllureApi Otherwise, there would be conflict between the class name and the root namespace name. Related to #404 * Add dynamic API functions (labels, links, name, description) Related to #404 * Split SetName into item-specific functions Related to #404 * Add new AllureApi functions to README * Add parameter functions to runtime API - SetTestParameter and UpdateTestParameter for adding and updating test parameters - historyId calculation adjusted to ignore excluded parameters - enum JSON serialization changed to camelcase (shouldn't affect anything) Related to #404 * Move historyId calculation to StopTestCase Motivation: more reliable, always takes into account the latest parameter set. * Factor out overwrite logic from AddLabel to new SetLabel fn Related to #404 * Put back and obsolete TestResult.AddParameter Related to #404 * Fix docs * Add SetLabel to README * Fix AllureApi name referred from Steps obsolete msg * Obsolete step logging - Move StepLogger from AllureApi back to CoreStepsHelper - Mark StepLogger as obsoleted - Remove step logging example from NUnit examples Related to #404 * Extract low-level step/fixture and lambda fixtures to ExtendedApi * Change parameter logic from set to add * Fix Allure.XUnit invalid call to AllureApi * Remove Set* API for labels (extracted to set-label-api) * Rename some API parameters * Fix #433
1 parent 7fc8d09 commit 51b6f15

56 files changed

Lines changed: 2699 additions & 885 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Allure.Features/Steps.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void StepWithAttach()
4949
{
5050
var path = Guid.NewGuid().ToString();
5151
File.WriteAllText(path, "hi there");
52-
allure.AddAttachment(path);
52+
AllureApi.AddAttachment(path);
5353
}
5454

5555
[StepDefinition("Step with table")]
@@ -104,8 +104,8 @@ private static void Handle(string[] tags)
104104
{
105105
var path = $"{Guid.NewGuid().ToString()}.txt";
106106
File.WriteAllText(path, "hi there");
107-
allure.AddAttachment(path);
108-
allure.AddAttachment(path, "text file");
107+
AllureApi.AddAttachment(path);
108+
AllureApi.AddAttachment(path, "text file");
109109
}
110110

111111
if (tags != null)

Allure.NUnit.Examples/AllureAsyncLifeCycleTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private async Task StepWithAttribute()
2929

3030
// use internally allure steps storage on different thread
3131
Console.WriteLine($" > AddAttachment...");
32-
AllureLifecycle.Instance.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value"));
32+
AllureApi.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value"));
3333
Console.WriteLine($" Done!");
3434
}
3535

@@ -61,7 +61,7 @@ private async Task StepLevel2()
6161

6262
// use internally allure steps storage on different thread
6363
Console.WriteLine($" > AddAttachment...");
64-
AllureLifecycle.Instance.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value"));
64+
AllureApi.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value"));
6565
Console.WriteLine($" Done!");
6666
}
6767
}

Allure.NUnit.Examples/AllureDiffTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Allure.Net.Commons;
22
using NUnit.Allure.Attributes;
3-
using NUnit.Allure.Core;
43
using NUnit.Framework;
54

65
namespace Allure.NUnit.Examples
@@ -20,16 +19,16 @@ public void DiffTest()
2019
public void DiffStepsTest()
2120
{
2221
AddDiffs();
23-
AllureLifecycle.Instance.WrapInStep(() =>
22+
AllureApi.Step("StepOutSide", () =>
2423
{
25-
AllureLifecycle.Instance.WrapInStep(() => { AddDiffs(); }, "Step Inside");
24+
AllureApi.Step("Step Inside", () => { AddDiffs(); });
2625
AddDiffs();
27-
}, "StepOutSide");
26+
});
2827
}
2928

3029
public static void AddDiffs()
3130
{
32-
AllureLifecycle.Instance.AddScreenDiff("Allure-Color.png", "Allure-Color.png", "Allure-Color.png");
31+
AllureApi.AddScreenDiff("Allure-Color.png", "Allure-Color.png", "Allure-Color.png");
3332
}
3433
}
3534
}

Allure.NUnit.Examples/AllureLabelTest.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public void CommonStaticLabelTest()
1919
[Test]
2020
public void CommonDynamicLabelTest()
2121
{
22-
AllureLifecycle.Instance.UpdateTestCase(t => t.labels.Add(Label.Epic("dynamic epic")));
23-
AllureLifecycle.Instance.UpdateTestCase(t => t.labels.Add(Label.Feature("dynamic feature")));
24-
AllureLifecycle.Instance.UpdateTestCase(t => t.labels.Add(Label.Story("dynamic story")));
25-
AllureLifecycle.Instance.UpdateTestCase(t => t.labels.Add(Label.Owner("dynamic owner")));
22+
AllureApi.AddEpic("dynamic epic");
23+
AllureApi.AddFeature("dynamic feature");
24+
AllureApi.AddStory("dynamic story");
25+
AllureApi.SetOwner("dynamic owner");
2626
}
2727

2828
[Test]
@@ -34,8 +34,7 @@ public void CustomStaticLabelTest()
3434
[Test]
3535
public void CustomDynamicLabelTest()
3636
{
37-
AllureLifecycle.Instance.UpdateTestCase(t =>
38-
t.labels.Add(new Label {name = "custom", value = "dynamic value"}));
37+
AllureApi.AddLabel("custom", "dynamic value");
3938
}
4039
}
4140
}

Allure.NUnit.Examples/AllureLinkTest.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ public void StaticLinkTest()
1919
[Test]
2020
public void DynamicLinkTest()
2121
{
22-
AllureLifecycle.Instance.UpdateTestCase(t => t.links.Add(Link.Issue("ISSUE-123")));
23-
AllureLifecycle.Instance.UpdateTestCase(t => t.links.Add(Link.Tms("TMS-123")));
24-
AllureLifecycle.Instance.UpdateTestCase(t =>
25-
t.links.Add(new Link {name = "GitHub", url = "https://github.com", type = "link"}));
22+
AllureApi.AddIssue("ISSUE-123", "123");
23+
AllureApi.AddTmsItem("TMS-123", "123");
24+
AllureApi.AddLink("GitHub", "https://github.com");
2625
}
2726
}
2827
}

Allure.NUnit.Examples/AllureSetUpTearDownTest.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.IO;
3+
using Allure.Net.Commons;
34
using NUnit.Allure;
45
using NUnit.Allure.Attributes;
5-
using NUnit.Allure.Core;
66
using NUnit.Framework;
77

88
namespace Allure.NUnit.Examples
@@ -15,10 +15,7 @@ public class AllureSetUpTearDownTest : BaseTest
1515
public void SetUp()
1616
{
1717
Console.WriteLine("I'm an unwrapped SetUp");
18-
StepsHelper.UpdateTestResult(tr =>
19-
{
20-
tr.name = "Some awesome name";
21-
});
18+
AllureApi.SetFixtureName("Fixture name changed in SetUp");
2219
Attachments.File("AllureConfig.json", Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json"));
2320
StepsExamples.Step1();
2421
}
@@ -28,31 +25,31 @@ public void SetUp()
2825
public void TearDown()
2926
{
3027
StepsExamples.Step3();
31-
StepsHelper.UpdateTestResult(tr =>
32-
{
33-
tr.name = "Some awesome name (changed on teardown)";
34-
});
28+
AllureApi.SetFixtureName("Fixture name changed in TearDown");
3529
Attachments.File("AllureConfig.json", Path.Combine(TestContext.CurrentContext.TestDirectory, "allureConfig.json"));
3630
}
3731

3832
[OneTimeSetUp]
3933
[AllureBefore("OneTimeSetUp AllureBefore attribute description")]
4034
public void OneTimeSetUp()
4135
{
36+
AllureApi.SetFixtureName("Fixture name changed in OneTimeSetUp");
4237
Console.WriteLine("I'm an unwrapped OneTimeSetUp");
4338
}
4439

4540
[OneTimeTearDown]
4641
[AllureAfter("OneTimeTearDown AllureAfter attribute description")]
4742
public void OneTimeTearDown()
4843
{
44+
AllureApi.SetFixtureName("Fixture name changed in OneTimeTearDown");
4945
Console.WriteLine("I'm an unwrapped OneTimeTearDown");
5046
}
5147

5248
[Test]
5349
[AllureSubSuite("Test Subsuite")]
5450
public void Test()
5551
{
52+
AllureApi.SetTestName("Test name changed in the test's body");
5653
StepsExamples.StepWithParams("first", "second");
5754
}
5855
}

Allure.NUnit.Examples/AllureStepLogTests.cs

Lines changed: 0 additions & 76 deletions
This file was deleted.

Allure.NUnit.Examples/AllureStepTest.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using Allure.Net.Commons;
33
using NUnit.Allure.Attributes;
4-
using NUnit.Allure.Core;
54
using NUnit.Framework;
65

76
namespace Allure.NUnit.Examples
@@ -37,27 +36,26 @@ public class AllureStepTest : BaseTest
3736
public void SimpleStepTest()
3837
{
3938
StepsExamples.Step1();
40-
AllureLifecycle.Instance.WrapInStep(() => { Console.WriteLine("Step 2"); }, "Step2");
39+
AllureApi.Step("Step2", () => { Console.WriteLine("Step 2"); });
4140
StepsExamples.Step3();
4241
}
4342

4443
[Test]
4544
[AllureName("Complex test with steps")]
4645
public void WrappedStepTest()
4746
{
48-
AllureLifecycle.Instance.WrapInStep(() =>
47+
AllureApi.Step("RootStep", () =>
4948
{
5049
StepsExamples.Step1();
5150

52-
AllureLifecycle.Instance.WrapInStep(() =>
51+
AllureApi.Step("Step2", () =>
5352
{
5453
Console.WriteLine("2");
55-
AllureLifecycle.Instance.WrapInStep(() => { Console.WriteLine("Step in step 2"); },
56-
"Step in Step 2");
57-
}, "Step2");
54+
AllureApi.Step("Step in Step 2", () => { Console.WriteLine("Step in step 2"); });
55+
});
5856

5957
StepsExamples.Step3();
60-
}, "RootStep");
58+
});
6159
}
6260

6361

Allure.NUnit/Attachments.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ namespace NUnit.Allure
77
public abstract class Attachments
88
{
99
public static void Text(string name, string content) => Bytes(name, Encoding.UTF8.GetBytes(content), ".txt");
10-
public static void Bytes(string name, byte[] content, string extension = "") => AllureLifecycle.Instance.AddAttachment(name, MimeTypesMap.GetMimeType(extension), content, extension);
11-
public static void File(string name, string path) => AllureLifecycle.Instance.AddAttachment(path, name);
10+
public static void Bytes(string name, byte[] content, string extension = "") =>
11+
AllureApi.AddAttachment(name, MimeTypesMap.GetMimeType(extension), content, extension);
12+
public static void File(string name, string path) =>
13+
AllureApi.AddAttachment(path, name);
1214
public static void File(string fileName) => File(fileName, fileName);
1315
}
1416
}

Allure.NUnit/Core/AllureNUnitHelper.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using NUnit.Framework;
1111
using NUnit.Framework.Interfaces;
1212
using NUnit.Framework.Internal;
13+
1314
using TestResult = Allure.Net.Commons.TestResult;
1415

1516
// ReSharper disable AccessToModifiedClosure
@@ -181,10 +182,6 @@ static void SetIdentifiers(ITest test, TestResult testResult)
181182
testResult.testCaseId = IdFunctions.CreateTestCaseId(
182183
testResult.fullName
183184
);
184-
testResult.historyId = IdFunctions.CreateHistoryId(
185-
testResult.fullName,
186-
testResult.parameters
187-
);
188185
}
189186

190187
static void SetLegacyIdentifiers(ITest test, TestResult testResult)
@@ -204,7 +201,11 @@ static void AddTestParametersFromNUnit(ITest test, TestResult testResult)
204201
var formatters = AllureLifecycle.TypeFormatters;
205202
foreach (var (name, value) in arguments)
206203
{
207-
testResult.AddParameter(name, value, formatters);
204+
testResult.parameters.Add(new()
205+
{
206+
name = name,
207+
value = FormatFunctions.Format(value, formatters)
208+
});
208209
}
209210
}
210211

@@ -299,7 +300,7 @@ private void AddConsoleOutputAttachment()
299300
.CurrentContext
300301
.CurrentResult
301302
.Output;
302-
AllureLifecycle.AddAttachment(
303+
AllureApi.AddAttachment(
303304
"Console Output",
304305
"text/plain",
305306
Encoding.UTF8.GetBytes(output),

0 commit comments

Comments
 (0)