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

Notification

Icon
Error

Colon in NUnit TestCase breaks ExclusivelyUsesAttribute
bartj
#1 Posted : Wednesday, December 4, 2013 10:47:32 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2013(UTC)
Posts: 26
Location: New Zealand

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
We would like to use the ExclusivelyUsesAttribute to prevent some issues with parallel execution of some legacy code. However, there appears to be a bug in this feature (NCrunch 1.48.0.5) when a colon is present in NUnit TestCase data. Below is a test that reproduces the issue. The tests should all run in parallel, but the test named "broken" does not pick up the ExclusivelyUsesAttribute. You can verify this by adding the "Exclusively Used Resources" column to the NCrunch Tests window.

Code:

using System;
using System.Threading;
using NCrunch.Framework;
using NUnit.Framework;

//Copied directly from the NCrunch documentation
namespace NCrunch.Framework
{
    public abstract class ResourceUsageAttribute : Attribute
    {
        private readonly string[] _resourceNames;

        public ResourceUsageAttribute(params string[] resourceName)
        {
            _resourceNames = resourceName;
        }

        public string[] ResourceNames
        {
            get { return _resourceNames; }
        }
    }

    public class ExclusivelyUsesAttribute : ResourceUsageAttribute
    {
        public ExclusivelyUsesAttribute(params string[] resourceName)
            : base(resourceName) { }
    }
}

namespace Demo
{
    [TestFixture]
    [ExclusivelyUses("Everything")]
    public class Class1
    {
        Mutex _testRunning = new Mutex(false, "TestLock");

        [SetUp]
        public void NewTestStarted()
        {
            if (!_testRunning.WaitOne(0))
                throw new InvalidOperationException("There should only be one test running at a time.");
        }

        [TearDown]
        public void TestCompleted()
        {
            _testRunning.ReleaseMutex();
        }

        [TestCase("okay","a")]
        [TestCase("okay", "b")]
        [TestCase("okay", "c")]
        [TestCase("okay", "d")]
        [TestCase("d", "cmkds:", TestName = "broken")]
        public void AllTestsShouldRunInSeries5(string dummy, string dummy2)
        {
            Thread.Sleep(3000);
        }
    }
}
Remco
#2 Posted : Wednesday, December 4, 2013 11:14:39 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi,

Thanks for reporting this issue. It looks like the test name is interfering with NCrunch's ability to properly identify the test method. I'll see if I can get this fixed.

You should be able to work around this problem by setting your Framework utilisation type for NUnit to StaticAnalysis. A drawback here is that you'll lose the granularity of your test cases - so it may be worth redesigning the test for the time being so that the colon isn't in the name.

Thanks again,

Remco
bartj
#3 Posted : Thursday, December 5, 2013 9:37:32 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/4/2013(UTC)
Posts: 26
Location: New Zealand

Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
Thanks for getting back to me so quickly.

We've worked around it by replacing colons with pipes in the TestCase and then performing a string replace on them within the test. This works for now, but is obviously not ideal, particularly because it is easy for developers to forget to apply the workaround when they write new tests.

Do you have any idea when this will be fixed?

Thanks,
Bart
Remco
#4 Posted : Thursday, December 5, 2013 10:20:55 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi Bart -

Right now I'm aiming to have this in the next v2 beta (v2.2b) expected to go out next week.
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.039 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download