How to exclude test case parameter from report in xUnit.net #2924
Replies: 2 comments
-
|
I've tried to implement something like this: [AttributeUsage(AttributeTargets.Method)]
public class AllureExcludeParameterAttribute(string parameterName) : BeforeAfterTestAttribute
{
public override void After(MethodInfo methodUnderTest)
{
AllureLifecycle.Instance.UpdateTestCase(tr =>
{
var parameter = tr.parameters.FirstOrDefault(p => p.name == parameterName);
if (parameter != null)
{
tr.parameters.Remove(parameter);
}
});
}
}But it does not work because when After is calling the parameter "tr.parameters" still empty. It's going to be populated on TestFinished event: https://github.com/allure-framework/allure-csharp/blob/main/Allure.Xunit/AllureMessageSink.cs#L155 |
Beta Was this translation helpful? Give feedback.
-
|
Hi, @vchistov ! Unfortunately, this is not currently possible. We will likely implement a way to preclude such parameters from the report in the future. We will also implement event listeners, which will help with such tasks, see allure-framework/allure-csharp#488. Unfortunately, I'm yet uncertain when exactly all these will be done. The best you can do right now is to provide a custom formatter, which will serialize objects of certain types as, say, empty strings: using Allure.Net.Commons;
class EmptyFormatter<T>: TypeFormatter<T>
{
public override string Format(T value) => "";
}Then the formatter should be registered somewhere once per each type. The easiest would be a module initializer: using System.Runtime.CompilerServices;
using Allure.Net.Commons;
static class SetUp
{
[ModuleInitializer]
internal static void Initialize()
{
AllureLifecycle.Instance.AddTypeFormatter(new EmptyFormatter<Mock<MyService>>());
AllureLifecycle.Instance.AddTypeFormatter(new EmptyFormatter<Mock<MyOtherService>>());
}
}Note, that will only work if the actual type of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Assume we have the following test case:
It will be cool to exclude myServiceMock from the allure report because it does not make sense. Does it possile? I found SkipAttribute (https://allurereport.org/docs/xunit-reference/#metadata), but it applicable for test step only.
Beta Was this translation helpful? Give feedback.
All reactions