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

Notification

Icon
Error

Support Interface‑Based Exclusive Resource Declarations
GreenMoose
#1 Posted : Monday, May 4, 2026 9:31:10 AM(UTC)
Rank: Advanced Member

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

Thanks: 147 times
Was thanked: 68 time(s) in 65 post(s)
Problem

Given a generic NUnit test fixture:

Code:

[TestFixture(typeof(SqlLiteInMemoryFixture))]
[TestFixture(typeof(SqlServerFixture))]
internal class CountryModelOperationsTest<T> : ExampleWebApiTest<T>
    where T : DbFixture<ExampleWebApiDbContext>, new()
{
    // tests...
}


I want NCrunch to treat only SqlServerFixture as an exclusive resource.
Today this requires creating a separate wrapper class:

Code:

[ExclusivelyUses("SqlServer")]
internal class CountryModelOperationsTest_SqlServer
    : CountryModelOperationsTest<SqlServerFixture>
{ }


This becomes tedious as the number of test classes grows, since the wrapper exists only to apply the NCrunch attribute.

Suggested enhancement

Allow NCrunch to detect exclusive resource usage via an interface implemented by any attribute.
This would let me declare exclusive resources without inheriting from NCrunch-specific attributes or creating wrapper test classes.

Example:

Code:

public interface IExclusivelyUses
{
    string ResourceName { get; }
}

public class SqlServerFixtureAttribute : TestFixtureAttribute, IExclusivelyUses
{
    public string ResourceName => "SqlServer";

    public SqlServerFixtureAttribute()
        : base(typeof(SqlServerFixture))
    {
    }
}
[SqlLiteInMemoryFixture]
[SqlServerFixture]
internal class CountryModelOperationsTest<T> : ExampleWebApiTest<T>
    where T : DbFixture<ExampleWebApiDbContext>, new()
{
    // tests...
}



If NCrunch recognized interfaces like IExclusivelyUses on attributes applied to fixtures or test classes,
it could treat the corresponding tests as exclusive without requiring derived test classes.
Users browsing this topic
Guest (5)
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.021 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download