Daily Usage Issues

Exclusively uses attribute per fixture type (NUnit) not working ?

Started by GreenMoose on 2,714 views

[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).


    [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
    {



[img=https://i.imgur.com/Hs2BmsP.png]Screenshot[/img]

Thanks.
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.
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...
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.
Remco 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.

Edited

Post a reply

Log in to reply.