SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

Make specflow config file name (specflow.json) configurable #2627

Closed epresi closed 1 year ago

epresi commented 2 years ago

Possible solution for #2546

Example usage:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <SpecFlowConfigFileName>specflow.dev.json</SpecFlowConfigFileName>
</PropertyGroup>

but it supports MsBuild properties as well:

<SpecFlowConfigFileName>$(AssemblyName).specflow.json</SpecFlowConfigFileName>

or whatever:

<SpecFlowConfigFileName>apple.json</SpecFlowConfigFileName>

If the SpecFlowConfigFileName is not specified, then the default value is used, which is specflow.json.

Sample test output/log:

  Standard Output: 
-> Loading plugin D:\Git\SpecFlowProject1\SpecFlowProject1\bin\Debug\net6.0\TechTalk.SpecFlow.MSTest.SpecFlowPlugin.dll
-> Loading plugin D:\Git\SpecFlowProject1\SpecFlowProject1\bin\Debug\net6.0\SpecFlowProject1.dll
-> Using apple.json

It's just adjusting the file name, if the content is not a valid specflow.json it will behave as before.

What is missing: adding some tests for full coverage, docs, changelog. Just opened the PR so that I'll get a review if it is worth the time to finish this PR.

Types of changes

Checklist:

epresi commented 2 years ago

What I realized in the meanwhile is that during building a SpecFlow project, the MsBuild.Generation writes to the output the used config: ConfigurationLoader Now the name of the config file is not the one I added, because of the GeneratorContainerBuilder's new container. SpecFlowConfigFileNameProvider is registered in the parentObjectContainer, not in the new container. Is there an elegant way to check if it is registered in the parent container? Because .IsRegistered<SpecFlowConfigFileNameProvider>() returns false on the child container (but it is possible to resolve it, I guess it resolves from the parent?!), therefore my code registers SpecFlowConfigFileNameProvider in the child container with the default value, which will be resolved later.

SabotageAndi commented 2 years ago

The registration issue we can figure out. But I think I am missing something. As I understood it, you convert the MSBuild property to an assembly attribute, which contains the configuration file name. But where do you read this value? At compile time you get it as MSBuild task parameter, but I don't see anything that uses Reflection at runtime to get the value. Am I blind? Or still to tired?

epresi commented 2 years ago

Yes, compile time it is a parameter, at runtime it is an assembly attribute. Reading and setting is done in the ContainerBuilder

SabotageAndi commented 2 years ago

Aaahh!

SabotageAndi commented 2 years ago

Is the issue in the Generator or at Runtime?

epresi commented 2 years ago

In Generator, Runtime is a bit different, there is no parent container, so it's registered in the right one.

gasparnagy commented 2 years ago

@SabotageAndi @lanfeust69 I have discussed this with @epresi, and I don't think it would be a good idea to make the config file configurable, because of the complications with the tooling (IDE extensions, etc.). I think we could find a better alternative for the original problem, without making this change in the SpecFlow core. I will share my ideas at the original issue.

gasparnagy commented 1 year ago

Closing it based on the comment earlier.