dennisroche / xunit.ioc.autofac

XUnit2 Test Framework implementation with Autofac
MIT License
20 stars 9 forks source link

The requested service 'Xunit.Sdk.TestOutputHelper' has not been registered. #6

Closed RavindraBarapatre closed 7 years ago

RavindraBarapatre commented 8 years ago

at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 parameters) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Result2 Message: Autofac.Core.Registration.ComponentNotRegisteredException : The requested service 'Xunit.Sdk.TestOutputHelper' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

dennisroche commented 8 years ago

You need to register an instance of ITestOutputHelper as described in the README.md.

builder.Register(context => new TestOutputHelper())
                .As<ITestOutputHelper>()
                .InstancePerLifetimeScope();
RavindraBarapatre commented 8 years ago

I followed all the steps as given in documentation. still I am getting same error.

dennisroche commented 8 years ago

That is odd. Can you provide a sample that reproduces the issue?

dennisroche commented 7 years ago

Closing. I'll reopen if sample/repo of the issue appears.

peterwurzinger commented 7 years ago

@dennisroche See http://stackoverflow.com/questions/43450788/xunit-test-with-autofac for a description in greater detail. Actually you have to register the TestOutputHelper also AsSelf() since the AutofacTestInvoker resolves an instance of this class.

So the correct way of initializing the Autofac-Infrastructure to get the library running could be

            builder.Register(context => new TestOutputHelper())
                .AsSelf()
                .As<ITestOutputHelper>()
                .InstancePerLifetimeScope();

You should consider adopting the README.md, I ran into the same problem today.

dennisroche commented 7 years ago

@peterwurzinger thanks. would you mind putting up a PR to update the README.md?

peterwurzinger commented 7 years ago

Sure, PR is up.