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

Notification

Icon
Error

Use of NUnit.Framework.RandomAttribute
John Brett
#1 Posted : Friday, November 30, 2012 1:29:59 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/1/2012(UTC)
Posts: 4
Location: Berkshire, UK

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I have a test that I've written to do some general sanity testing of a degenerate class
(NullRules, an implementation of an interface I have which always returns the same value).
Since I don't care specifically what the test data is, I used NUnit's RandomAttribute to have
the test runner randomly generate a handful of test data and run it through.

This works fine in the GUI, the console runner and Resharper.
However, NCrunch is unable to execute them.


Code:
    public class NullRules
    {
        public NullRules(int defaultValue)
        {
            DefaultValue = defaultValue;
        }

        #region Implementation of IRules

        public int ApplyRules(params object[] properties)
        {
            return DefaultValue;
        }

        public int DefaultValue { get; private set; }

        #endregion
    }

        [Test]
        public void TestNullRules([Random(0,1000,10)] int value)
        {
            var sut = new NullRules(value);
            var actual = sut.ApplyRules(false, 12321, 88.233, DateTime.Today, true, 912);
            Assert.That(actual, Is.EqualTo(value));
        }

Remco
#2 Posted : Friday, November 30, 2012 10:59:49 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi John -

NUnit's Random attribute generates Random test names, which cause confusion for NCrunch when trying to match up tests between its analysis and execution. You can make these tests work by setting your 'Framework Utilisation Type' for NUnit to 'StaticAnalysis' under your NCrunch solution configuration. You can find some more information about this configuration setting in the documentation.


Cheers,

Remco
1 user thanked Remco for this useful post.
John Brett on 12/3/2012(UTC)
John Brett
#3 Posted : Monday, December 3, 2012 7:35:03 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/1/2012(UTC)
Posts: 4
Location: Berkshire, UK

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
I thought it would be something like that.
Thanks for the work-around.
To be honest, having the full features of NCrunch is worth some minor aggravation with this particular edge-case, so I've left my Framework Utilisation at Dynamic and changed my testcase.

John
1 user thanked John Brett for this useful post.
Remco on 12/3/2012(UTC)
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.030 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download