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

Notification

Icon
Error

Exclusively uses attribute per fixture type (NUnit) not working ?
GreenMoose
#1 Posted : Monday, March 25, 2019 7:29:11 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
[v3.24.0.5]

So I have a generic NUnit fixture, where the type argument decides if it going to hit SQLServer or SQLite resource. Bug? Or is there some other a way I can tell NCrunch that the SQLServer category is exclusively using SQL Server, but SQLite is not?
(Below makes both fixture types "exclusively use" SqlServer resource).

Code:

    [TestFixture(TypeArgs = new[] {typeof(GenApiClientSqlServerTestDomain)}, Category = TestCategories.cSqlServer)]
    [TestFixture(TypeArgs = new[] {typeof(GenApiClientSqliteInMemoryTestDomain)}, Category = TestCategories.cSqlite), ExclusivelyUses(TestCategories.cSqlServer)]
    internal class CanResolveDbServicesTest<TDomain> : GenApiClientDbTest<TDomain>
        where TDomain : GenApiClientDbTestDomain
    {



Screenshot

Thanks.
Remco
#2 Posted : Monday, March 25, 2019 11:49:16 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Thanks for sharing this. The behaviour here is as designed, though it isn't intuitive. In this situation, it's the best we can do because of the design of the CLR.

As far as CIL is concerned, attributes declared in the following manner have the same physical result in the assembly:

[MyAttribute1, MyAttribute2]
public void MyTest()

[MyAttribute1]
[MyAttribute2]
public void MyTest()

Even though you've stacked the attributes into the same declaration, there's no physical way to separate them once they go through the compiler. So by adding ExclusivelyUses to the end of your TestFixture line, you've made all tests in this class exclusively use cSqlServer.
GreenMoose
#3 Posted : Tuesday, March 26, 2019 8:22:41 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
I see, what a bummer. And I thought I had found the ultimate setup :D

Is there any other means of making this "exclusively uses" behavior happen given above setup? The only way I see is to create a system mutex that is applied only when test is using a specific NUnit test category (i.e. SqlServer), but then that would delay test itself when running and give inaccurate execution durations.

And the only "missing feature" I can think of is a new filter e.g. "Tests to not execute in parallel" and then be able to enter a filter similar to automatically execution filter, but maybe that isn't that bad for a feature request...
Remco
#4 Posted : Tuesday, March 26, 2019 11:29:26 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Without implementing your own Mutex, ExclusivelyUsesAttribute is the only way to create this kind of restriction inside the engine. Something you could try is splitting the TestFixture class into two derived classes each with their own attribute declaration.

We do have SerialAttribute to determine which tests cannot be run in parallel, but again, this is an attribute.
GreenMoose
#5 Posted : Wednesday, March 27, 2019 9:50:27 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 6/17/2012(UTC)
Posts: 507

Thanks: 145 times
Was thanked: 66 time(s) in 64 post(s)
Remco;13273 wrote:
Something you could try is splitting the TestFixture class into two derived classes each with their own attribute declaration.


The idea here is to have x number of generic types which decides on which infrastructure to execute the tests on (SqlServer/MongoDb/SQLite etc.) and these can be placed on any fixture thus creating X empty derived fixtures for every fixture containing the tests is not a feasible route forward.

I'll go with the system mutex route then, 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.037 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download