allure-framework / allure-framework/allure-csharp

Add support for async step functions returning ValueTask

Open
#456 0 comments 0 reactions 0 assignees View on GitHub
good first issue task:new feature theme:core
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

![image](https://github.com/allure-framework/allure-csharp/assets/17935127/89516fe8-791f-4743-961d-1144a50f56e3)

#### 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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.