Build/Test Issues

Use of NUnit.Framework.RandomAttribute

Started by John Brett on 6,630 views

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.


    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));
        }

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

Post a reply

Log in to reply.