CSharp Nunit - Unwrap TargetInvocationException #2590
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hello:) Good work . I am newbie in Alure Framework and faced with problem [TestCase(Author = "XXXXX", Description = "XXXX")]
[AllureTag("XXXX", "NEGATIVE")]
[AllureLink("Test-case #449922", "XXX/project/1249/test-cases/449922?treeId=2900")]
public void FFFFTests()
{
FFFFStep();
}
[AllureStep("Action 4: ")]
public void FFFFStep()
{
Assert.Fail("FFFFReserveCounterWithErrorsStep Test Alure");
}
[TestCase(Author = "XXXX", Description = " Some Description")]
[AllureTag("RESERVECOUNTER", "NEGATIVE")]
[AllureLink("Test-case #449922", "XXX/project/1249/test-cases/449922?treeId=2900")]
public void AAAATest()
{
AllureApi.Step("Ssep + {}",()=>{
Assert.Fail("dinamic step AAAAStep ");
});
} That after FFFFTests and allure framework sets Test status as broken
But it is no work for me (i dont know why, may be i should read configuratin from the json file via code)
and
Ithink i get your implementation with search acceptable Exception Types in exception stack (I think i should take it from configuration ) |
Beta Was this translation helpful? Give feedback.
-
I did manage to solve this issue by changing my approach a little bit, instead of trying to override the actual allure aspect, I created one separate aspect that wraps around the base aspect. In order to do this we need to handle all type of function that we might get there (generics, tasks, etc...), for this purpose I used the library Aspect.Universal by the same contributors of the underlying AspectInjector used in Allure. Basically the code now looks like this. namespace TestAllureWrap;
[Aspect(Scope.Global)]
public class WrapInvokeAspect : BaseUniversalWrapperAspect
{
[Advice(Kind.Around, Targets = Target.Method | Target.Constructor)]
public new object Around(
[Argument(Source.Instance)] object instance,
[Argument(Source.Type)] Type type,
[Argument(Source.Metadata)] MethodBase method,
[Argument(Source.Target)] Func<object[], object> target,
[Argument(Source.Name)] string name,
[Argument(Source.Arguments)] object[] args,
[Argument(Source.ReturnType)] Type returnType,
[Argument(Source.Triggers)] Attribute[] triggers
)
{
try
{
return BaseHandle(instance, type, method, target, name, args, returnType, triggers);
}
catch (TargetInvocationException ex)
{
Exception wrappedException = ex;
while (wrappedException is TargetInvocationException && wrappedException.InnerException is not null)
{
wrappedException = wrappedException.InnerException;
}
if (wrappedException is not TargetInvocationException)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(wrappedException);
throw;
}
}
}
[Injection(typeof(AllureStepAspectBase), Priority = 0)]
[Injection(typeof(WrapInvokeAspect), Priority = 1)]
public class CustomStepAttribute : AbstractStepAttribute; |
Beta Was this translation helpful? Give feedback.
-
Thank you . I 'll try your approch.
May be we should find in this loop exception that should be thrown using allure Configuration |
Beta Was this translation helpful? Give feedback.
I did manage to solve this issue by changing my approach a little bit, instead of trying to override the actual allure aspect, I created one separate aspect that wraps around the base aspect. In order to do this we need to handle all type of function that we might get there (generics, tasks, etc...), for this purpose I used the library Aspect.Universal by the same contributors of the underlying AspectInjector used in Allure. Basically the code now looks like this.