Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

ITestOutputHelper unavailable when using SpecFlow.xUnit #75

Closed
rangers-globecar opened this issue Jan 13, 2022 · 16 comments · Fixed by #87
Closed

ITestOutputHelper unavailable when using SpecFlow.xUnit #75

rangers-globecar opened this issue Jan 13, 2022 · 16 comments · Fixed by #87
Assignees
Labels
enhancement New feature or request

Comments

@rangers-globecar
Copy link

rangers-globecar commented Jan 13, 2022

Hi,
We are using SpecFlow.xUnit; is there anyway to add/capture the ITestOutputHelper, in the same way [Binding] are being automatically ?

@mbhoek mbhoek self-assigned this Jan 24, 2022
@mbhoek mbhoek added the question Further information is requested label Jan 24, 2022
@mbhoek
Copy link
Member

mbhoek commented Jan 24, 2022

Interesting question @robert-stratecglobal -- although it's not related to the Microsoft.DependencyInjection framework specifically, I can understand you want this xUnit feature to work.

I've created a test which should cover this issue and committed it in the https://github.com/solidtoken/SpecFlow.DependencyInjection/tree/feature/75-ITestOutputHelper branch. Let me know if this truly the issue you're talking about.

The challenge imho is to solve this without SpecFlow.DependencyInjection needing a dependency on xUnit specifically. I'll need some time to further investigate and think of a correct way to solve this.

@mbhoek mbhoek added help wanted Extra attention is needed and removed question Further information is requested labels Jan 24, 2022
@bobbyangers
Copy link

bobbyangers commented Jan 24, 2022

The ISpecflowOutputHelper could be an alternative that would work as well.

Isn't there a way to "pickup" what is in the BoDi ? That way, any future enhancement to the DI and any third party plugin would automatically insert as well...

@bobbyangers
Copy link

bobbyangers commented Jan 25, 2022

 public class TestService : ITestService {

     public TestService(ISpecflowOutputHelper output)    //or ITestOutputHelper
     {
               //This is what I would like
     }
}

@mbhoek
Copy link
Member

mbhoek commented Jan 26, 2022

Isn't there a way to "pickup" what is in the BoDi ? That way, any future enhancement to the DI and any third party plugin would automatically insert as well...

That would make sense @bobbyangers but the current implementation completely replaces BoDi. So either it needs to fall back to BoDi if a dependency cannot be found in Microsoft's IServiceCollection (seems hard and might break existing implementations), or we add the dependencies available in BoDi to the IServiceCollection explicitly (requires bit of extra setup but should not break existing implementations).

I'll investigate the latter.

@rangers-globecar
Copy link
Author

rangers-globecar commented Jan 26, 2022

@mbhoek

Check out Corvus.Testing

they have an elegant way of handling the problem.... by using "hooks".... it's possible to "inject" more stuff and even do 'automatically' do some stuff in the background....

@304NotModified
Copy link
Contributor

304NotModified commented Mar 11, 2022

https://github.com/AdCodicem/SpecFlowMicrosoftDependencyInjection

solved it with the AddDelegated (so no dependency on xUnit from the lib)

    public void ConfigureServices(IServiceCollection services)
    {
        services
            // ITestOutputHelper is automatically registered by Specflow when using xUnit runner
            .AddDelegated<ITestOutputHelper>() ///!< ------------------
            // Calculator can use ITestOutputHelper as it's registered above to delegate the resolution to the original container
            .AddTransient<ICalculator, Calculator>();
    }

Good logging is essential, so I also need the ITestOutputHelper

@mbhoek mbhoek added enhancement New feature or request and removed help wanted Extra attention is needed labels Mar 11, 2022
@mbhoek
Copy link
Member

mbhoek commented Mar 11, 2022

@304NotModified Do you mind if I copy/paste your AddDelegated solution into this project?

@304NotModified
Copy link
Contributor

It isn't mine ;)

@mbhoek
Copy link
Member

mbhoek commented Mar 11, 2022

Right, sorry. @AdCodicem was involved early on but created their own plugin instead, apologies for the mix-up.
I'll see what I can do!

@AdCodicem
Copy link

@mbhoek You can do copy anything you need from my repo, I think it's better to have only one project to maintain, and as I started a company of my own, I have less time to spend on my project.

If it's ok for you I'll add a message to redirect the users to your project 🙂

@mbhoek
Copy link
Member

mbhoek commented Mar 11, 2022

@AdCodicem Congratulations on starting your own company! I'm happy to keep maintaining this project, I think we've had a couple of great contributions over time. I do however struggle with available time too. I'll take some time this weekend to look at your code and @shlomiassaf 's PR #74 and see how we can make this the best MDI plugin available.

Of course I will keep on crediting all contributors. Thanks again!

@mbhoek mbhoek pinned this issue Mar 11, 2022
@mbhoek mbhoek linked a pull request Mar 11, 2022 that will close this issue
@mbhoek
Copy link
Member

mbhoek commented Mar 11, 2022

Guess this plugin is not the only one struggling with this issue: https://github.com/SpecFlowOSS/SpecFlow/issues/2550

Also want to track this one: https://github.com/SpecFlowOSS/SpecFlow/issues/2353

@AdCodicem
Copy link

Thank you! Don't hesitate to ask me if you need any help 🙂

This was referenced Mar 12, 2022
@mbhoek
Copy link
Member

mbhoek commented May 19, 2022

@AdCodicem I'm trying to figure out whether I want to copy your IServiceConfigurator pattern or just stick to the static implementation currently in this plugin. Can you explain a bit about your thinking behind it?

@AdCodicem
Copy link

AdCodicem commented May 19, 2022

@mbhoek the IServiceConfigurator purpose is to enable services registration in several configuration classes, at the time I needed to separate some configuration for readability.

You can see in this part of the code where the plugin search for IServiceConfigurator implementations :

https://github.com/AdCodicem/SpecFlowMicrosoftDependencyInjection/blob/435c84e052208bd1b207e9fafcced2fc62e94f9b/AdCodicem.SpecFlow.MicrosoftDependencyInjection/DependencyInjectionPlugin.cs#L42-L48

Edit:
Also, I wanted to manage the creation of the Service collection and the interface allowed me to restrict the way the developer implemented the ConfigurationServices method and so, less issues ensued

@mbhoek
Copy link
Member

mbhoek commented May 22, 2022

@robert-stratecglobal @bobbyangers ISpecFlowOutputHelper (and other SpecFlow infrastructure) is available in release v3.9.3.

@mbhoek mbhoek unpinned this issue May 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
5 participants