allure-framework / allure-framework/allure-csharp
Add support for async step functions returning ValueTask
- Dominant language
- C#
- Stars
- 125
- Forks
- 76
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 18
Description
#### I'm submitting a ...
- [ ] bug report
- [x] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
#### What is the current behavior?
#### If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
Given the following test:
```c#
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Allure.Attributes;
class MyTestClass
{
[Test]
public async ValueTask MyTest()
{
await MyStep();
[AllureStep]
static async ValueTask MyStep()
{
await Task.Delay(1000);
throw new Exception();
}
}
}
```
The following can be observed:
- The step's status is incorrectly set to `passed`
- The step's duration is unexpectedly low

#### What is the expected behavior?
- The step's status is `broken`.
- The step's duration is close to 1000ms.
#### Please tell us about your environment:
- Allure version: 2.25.0
- Test framework: NUnit@4.1.0
- Allure adaptor: Allure.NUnit@2.11.0
#### Other information
The issue occurs because the aspect doesn't await the return value of the step in a manner similar to how it's done for steps returning `Task` or `Task`. We check for `Task` and `Task` explicitly, so we should add similar branches for `ValueTask` and `ValueTask` (the [System.Threading.Tasks.Extensions](https://www.nuget.org/packages/System.Threading.Tasks.Extensions) package should be used to access the types).
Contributor guide
Research direction
Start with the aspect code that handles step methods returning Task and Task, then compare it with the provided NUnit example using ValueTask. Verify handling for ValueTask and ValueTask with the System.Threading.Tasks.Extensions types. Done means the exception produces a broken step status and the recorded duration is close to the awaited delay.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100