Skip to content

Allure reports are not generated if add dependency "Xunit.dependencyInjection(7.2.0)" to project packages #10

Open
romart333 opened this issue Jun 2, 2021 · 3 comments

Comments

@romart333
Copy link

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

Screenshot_2 png

@IvanWR1995
Copy link
Contributor

Hello. Thank your for issue report, @romart333 .
We will think out on this issue, and come with our feedback.

Faithfully yours,
Ivan

@tkeerthivel
Copy link

tkeerthivel commented Apr 28, 2022

Team, any timeline on this? Still not able to use Allure reports with Xunit dependency injection. Please look into this.

@pos777
Copy link

pos777 commented May 26, 2022

It looks like the issue is related to Xunit.DependencyInjection itself. Refer to the similar issue pengweiqhca/Xunit.DependencyInjection#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>());
        }
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants