Allure.XUnit
Allure.XUnit copied to clipboard
Allure reports are not generated if add dependency "Xunit.dependencyInjection(7.2.0)" to project packages
If add Xunit.dependencyInjection nugget package and Startup class to .NET project then allure reports stop being created. I suppose it's a matter of changing the entry point to the application
Hello. Thank your for issue report, @romart333 . We will think out on this issue, and come with our feedback.
Faithfully yours, Ivan
Team, any timeline on this? Still not able to use Allure reports with Xunit dependency injection. Please look into this.
It looks like the issue is related to Xunit.DependencyInjection itself. Refer to the similar issue https://github.com/pengweiqhca/Xunit.DependencyInjection/issues/46.
As a workaround, it should be possible to define a custom Xunit.DependencyInjection.IXunitTestCaseRunnerWrapper
and duplicate the logic of the AllureXunitTestCase.RunAsync method in it:
using Allure.Xunit;
using Allure.XUnit;
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace Xunit.DependencyInjection.AllureXUnit
{
public class AllureXunitTestCaseRunnerWrapper : DependencyInjectionTestCaseRunnerWrapper
{
private static readonly Type testCaseType;
private static readonly PropertyInfo testResultAccessor;
static AllureXunitTestCaseRunnerWrapper()
{
testCaseType = typeof(Steps).Assembly.GetType("Allure.XUnit.AllureXunitTestCase");
testResultAccessor = typeof(Steps).GetProperty("TestResultAccessor", BindingFlags.NonPublic | BindingFlags.Static);
}
public override Type TestCaseType => testCaseType;
public override Task<RunSummary> RunAsync(IXunitTestCase testCase, IServiceProvider provider,
IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments,
ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource)
{
testResultAccessor.SetValue(default, testCase);
messageBus = new AllureMessageBus(messageBus);
return base.RunAsync(testCase, provider, diagnosticMessageSink, messageBus,
constructorArguments, aggregator, cancellationTokenSource);
}
}
}
Then register it as a service:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Xunit.DependencyInjection;
using Xunit.DependencyInjection.AllureXUnit;
namespace Allure.XUnit.Examples
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.TryAddEnumerable(ServiceDescriptor.Singleton<IXunitTestCaseRunnerWrapper, AllureXunitTestCaseRunnerWrapper>());
}
}
}