allure-framework / allure-framework/allure-csharp
ArgumentNullException when calling a local function with a captured value and [AllureStep]
- Dominant language
- C#
- Stars
- 125
- Forks
- 76
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 18
Description
#### I'm submitting a ...
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
#### What is the current behavior?
An attribute-based step can't be added with a local non-static method that captures a variable from an outer scope.
#### If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
The following test fails with `ArgumentNullException`
```c#
class MyTestClass
{
[Test]
public void MyTest()
{
var v = 0;
Step();
[AllureStep]
int Step() => v;
}
}
```
#### Please tell us about your environment:
- Allure version: 2.25.0
- Test framework: nunit@4.1.0
- Allure adapter: Allure.NUnit@2.11.0
Other adapters are most probably affected, too.
#### Other information
The compiler converts each captured value into a method's parameter. That parameter's `Name` property is set to null, leading to `ArgumentNullException` when the method's parameters are used to construct the step's title and parameters.
The null value is accessed [here](https://github.com/allure-framework/allure-csharp/blob/b8a1786d39c2738930c596b6f5e16f5fd0bee4d8/Allure.Net.Commons/Steps/AllureStepParameterHelper.cs#L75) and [here](https://github.com/allure-framework/allure-csharp/blob/b8a1786d39c2738930c596b6f5e16f5fd0bee4d8/Allure.Net.Commons/Steps/AllureStepParameterHelper.cs#L149)
Contributor guide
Research direction
Start with Allure.Net.Commons/Steps/AllureStepParameterHelper.cs, especially the parameter handling at the two locations linked in the issue, and run the supplied NUnit reproduction. Trace how captured local-function parameters are used for the step title and parameters. Done means the reproduction no longer throws ArgumentNullException and the generated step data remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100