It allows me to group a few steps by business logic, represent it as a hierarchical tree in allure reports and write high-order test scenario like:
"Open Preference Window".Step(() =>
{
"Login".Step(() => { /* Do many staff */});
ClickHere();
ClickThenHere();
ClickTheLastOne();
});
But I've found that if some exception appears in the Action (Delegate), allure shows a useless message like:
System.ArgumentException : ohohoh
Data:
Rethrow: True
at Allure.Commons.AllureLifecycle.StepRunner[TResult](String stepName, Delegate del, Boolean throwEx, Status stepStatusIfFailed, Object[] stepParams)
at Allure.Commons.AllureLifecycle.RunStep(String stepName, Action stepBody, Object[] stepParams)
at <...>.StringExtensions.Step(String s, Action stepBody, Object[] stepParams) in <...>\StringExtensions.cs:line 47
at <...>.EmptyDataSource() in <...>\DataSourceTests.cs:line 188
So I can't understand what has happened in the Delegate.
To Reproduce
Throw any unhandled exception inner the Action stepBody.
Expected behavior
As I would like to know what has happened I have written my own dummy RunStep analog:
public static void Step(this string s, Action stepBody)
{
var stepStatus = Status.passed;
var throwedEx = (Exception) null;
var str = $"{(object) Guid.NewGuid():N}";
AllureLifecycle.Instance.StartStep(str, new StepResult
{
name = s, start = AllureLifecycle.ToUnixTimestamp(DateTimeOffset.Now)
});
try
{
stepBody();
}
catch (Exception ex)
{
throwedEx = ex;
stepStatus = Status.failed;
}
finally
{
AllureLifecycle.Instance.UpdateStep(step => step.status = stepStatus);
AllureLifecycle.Instance.StopStep(str);
}
if (null != throwedEx)
ExceptionDispatchInfo.Capture(throwedEx).Throw();
}
All magic hidden in the ExceptionDispatchInfo.Capture(throwedEx).Throw();, so allure says:
System.ArgumentException : ohohoh
at <...>.DataSourceCommon`1.SetTag(String tag) in <...>\DataSourceCommon.cs:line 31
at <...>.DataSourceTests.<>c__DisplayClass2_1.<EmptyDataSource>b__0() in <...>\DataSource\DataSourceTests.cs:line 192
at <...>.StringExtensions.Step(String s, Action stepBody) in <...>\StringExtensions.cs:line 31
--- End of stack trace from previous location where exception was thrown ---
at <...>.StringExtensions.Step(String s, Action stepBody) in <...>\StringExtensions.cs:line 45
at <...>.EmptyDataSource() in <...>\DataSourceTests.cs:line 188
As you can see the first block describes inner Action exception, the second is the rethrown exception by Step itself. It gives much more useful info.
Describe the bug I have a convenient extension:
It allows me to group a few steps by business logic, represent it as a hierarchical tree in allure reports and write high-order test scenario like:
But I've found that if some exception appears in the
Action
(Delegate), allure shows a useless message like:So I can't understand what has happened in the Delegate.
To Reproduce Throw any unhandled exception inner the
Action stepBody
.Expected behavior As I would like to know what has happened I have written my own dummy
RunStep
analog:All magic hidden in the
ExceptionDispatchInfo.Capture(throwedEx).Throw();
, so allure says:As you can see the first block describes inner
Action
exception, the second is the rethrown exception by Step itself. It gives much more useful info.So, what do you think about replacing
to
? Have you any other suggestions?
Versions