forked from allure-framework/allure-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for async NUnit tests allure-framework#303
- Loading branch information
Showing
6 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# indent_style : { "tab", "space" } | ||
# indent_size : { an integer } | ||
# tab_width : { optional positive integer (defaults "indent_size" when "indent_size" is a number) } | ||
# end_of_line : { "lf", "cr", "crlf" } | ||
# charset : { "latin1", "utf-8", "utf-16be", "utf-16le" } | ||
# trim_trailing_whitespace : { "true", "false" } | ||
# insert_final_newline : { "true", "false" } | ||
# max_line_length : { positive integers } | ||
|
||
root = true | ||
|
||
[*] | ||
trim_trailing_whitespace = true | ||
insert_final_newline = false | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[*.{cs,csproj}] | ||
charset = utf-8-bom | ||
indent_style = space | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Allure.Net.Commons; | ||
using NUnit.Allure.Attributes; | ||
using NUnit.Allure.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Allure.NUnit.Examples | ||
{ | ||
[AllureNUnit] | ||
public class AllureAsyncLifeCycleTests | ||
{ | ||
[Test] | ||
public async Task AsyncTest_With_AllureStepAttribute() | ||
{ | ||
Console.WriteLine("> Сalling async method with [AllureStep] ..."); | ||
await StepWithAttribute(); | ||
Console.WriteLine(" Done!"); | ||
} | ||
|
||
[AllureStep("Calling StepWithAttribute")] | ||
private async Task StepWithAttribute() | ||
{ | ||
// switching thread on async | ||
Console.WriteLine($" > Delay..."); | ||
await Task.Delay(1000); | ||
Console.WriteLine($" Done!"); | ||
|
||
// use internally allure steps storage on different thread | ||
Console.WriteLine($" > AddAttachment..."); | ||
AllureLifecycle.Instance.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value")); | ||
Console.WriteLine($" Done!"); | ||
} | ||
|
||
[Test] | ||
public async Task AsyncTest_With_WrapInStep() | ||
{ | ||
Console.WriteLine("> StepLevel1..."); | ||
await AllureLifecycle.Instance.WrapInStepAsync( | ||
async () => await StepLevel1() | ||
); | ||
Console.WriteLine(" Done!"); | ||
} | ||
|
||
private async Task StepLevel1() | ||
{ | ||
Console.WriteLine(" > StepLevel2..."); | ||
await AllureLifecycle.Instance.WrapInStepAsync( | ||
async () => await StepLevel2() | ||
); | ||
Console.WriteLine(" Done!"); | ||
} | ||
|
||
private async Task StepLevel2() | ||
{ | ||
// switching thread on async | ||
Console.WriteLine($" > Sleep..."); | ||
await Task.Delay(1000); | ||
Console.WriteLine($" Done!"); | ||
|
||
// use internally allure steps storage on different thread | ||
Console.WriteLine($" > AddAttachment..."); | ||
AllureLifecycle.Instance.AddAttachment("attachment-name", "text/plain", Encoding.UTF8.GetBytes("attachment-value")); | ||
Console.WriteLine($" Done!"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters