Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

testing a dotnet core class library with Specflow #46

Closed
jimdeane opened this issue Mar 30, 2017 · 4 comments
Closed

testing a dotnet core class library with Specflow #46

jimdeane opened this issue Mar 30, 2017 · 4 comments

Comments

@jimdeane
Copy link

I've been trying to understand what this means for a couple of days now. My understanding (probably totally wrong) was that i could use VS2017 to develop a DOTNET CORE class library and then test it using another DOTNET CORE Test Project, using the SpecFlow.NetCore NuGet package (and modifications to the app.config).

The behaviour appears conflicting.

The .feature.cs gets generated but the Techtalk.Specflow library is missing.

If I include SpecFlow 2.1.0 the build fails with incompatible .net versions.

Am I simply trying to use this in an impossible way or is there a workaround.

We use Specflow universally and a attempting to start a DOTNET CORE project right now and failing miserable.

Thnaks

@igor-1024
Copy link

Hi Jim! I had exactly the same problems: “.feature.cs” gets generated with TechTalk references or I get “incompatible .NET versions” error. I ended up moving all of the logic out into a separate .NETStandard 1.4 class library, referenced it by original .NETCoreApp 1.1 project and had .NET 4.6.1 SpecFlow Test project testing just the business logic in 1.4 class library the “old” way.

@stajs
Copy link
Owner

stajs commented Mar 30, 2017

As @erik-lundgren mentioned, it is a case of SpecFlow still being stuck on full framework (see #39).

@igor-1024's suggestion is the best workaround for now.

@stajs stajs closed this as completed Mar 30, 2017
@tomitrescak
Copy link

trying to understang @igor-1024 's approach. How exactly do you refrence .NET core projects from NET4.6? I tried but it's not doable.

@smudge202
Copy link
Contributor

smudge202 commented Jan 11, 2018

My original reply was wrong so have replaced it with this:

@tomitrescak by default, your class libraries target netcoreapp2.0 (this is a mistake in the templates if you ask me). However, most of the net core ecosystem (MVC for example), if you check out their dependencies on NuGet, actually target netstandard2.0. If you change your class library to also target netstandard2.0 (edit the csproj) then both the net462 and netcoreapp2.0 platforms are able to reference the library.

There is a downside to doing this however - the platforms implement netstandard differently, and there could be a difference in behaviour at times. MS strive to avoid this but don't always succeed. Therefore, if you test a netstandard library against net462 in order to allow specflow to run, but in production you run the app using the netcoreapp platform, there could (though shouldn't) be slight differences.

Unfortunately, if you want SpecFlow to be involved, there's no real way around this right now. Ideally, your test project would multi-target both net462 and netcoreapp2.0 in order to test against both platforms (this kind of thing isn't even supported by the VS Test Explorer yet, but is something both supported by and preached for xUnit / Brad Wilson).

TL;DR: Try targeting your class library at netstandard2.0 (hopefully your nuget dependencies all support this). If the code your testing is an application, move the code into a class library and test it there.

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

5 participants