Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Ignore test projects based on target frameworks
distilled
#1 Posted : Saturday, February 6, 2021 6:14:30 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/3/2012(UTC)
Posts: 22

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
I use NCrunch in solutions with .NET Standard projects. When I create test projects for them, I multi-target the runtimes that I expect my .NET Standard libraries to run on (so if Foo.csproj targets NETStandard2.0, FooTests.csproj probably targets net46, netcoreapp3.1, etc.). NCrunch treats each target runtime as separate projects and runs them independently - which is the behavior that I would expect. The downside of this is that it multiplies the number of tests that NCrunch monitors and processes.

I like the way that NCrunch handles this situation by default and I wouldn't want that behavior to go away. However, there are many times when I'd like to be able to tell NCrunch to only automatically run tests for one specific runtime, and ignore the other runtimes unless I manually run them. For example, assuming I have FooTests.csproj with <TargetFrameworks>net48;netcoreapp2.2;netcoreapp3.1</TargetFrameworks>:

FooTests.csproj (net48): automatically run any of these that are impacted by my changes
FooTests.csproj (netcoreapp2.2): don't automatically run these even if they're impacted. I'll run them manually if or when I need to
FooTests.csproj (netcoreapp3.0): same as above, only run manually

Is there a way to configure NCrunch that accomplishes this?
Remco
#2 Posted : Saturday, February 6, 2021 10:37:38 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,976

Thanks: 930 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting.

The easiest way I can think of doing this is to introduce assembly-level category attributes in your test project which are controlled by framework-specific compile switches.

For example:

#if NETCOREAPP2_2
[assembly: NCrunch.Framework.Category("NetCore2_2")]
#endif

#if NETCOREAPP3_0
[assembly: NCrunch.Framework.Category("NetCore3_0")]
#endif

#if NET48
[assembly: NCrunch.Framework.Category("Net48")]
#endif

In this way, every test in the assembly will have a category assigned to it that is tied to the platform it targets.

You can then set the Tests to execute automatically setting with consideration to the above categories, ideally doing so with some custom engine modes. This way you can set the engine to run tests for specific platforms depending on your selected engine mode.
1 user thanked Remco for this useful post.
distilled on 2/7/2021(UTC)
distilled
#3 Posted : Sunday, February 7, 2021 10:56:34 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/3/2012(UTC)
Posts: 22

Thanks: 2 times
Was thanked: 6 time(s) in 6 post(s)
That sounds reasonable, I'll take that approach. Thanks!
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.028 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download