Setup Problems

MbUnit DependsOn attribute seems to be ignored

Started by espenalb on 7,383 views

I recently discovered nCrunch - and I am impressed, and feel it greatly improves my TDD!

However, I got one problem - when nCrunch tries to execute a test I have written that uses the MbUnit "DependsOn" feature. I use this feature in a test where I test "Normal usage" - and this testfixture requires each test to be executed in the correct order.

Here is a sample that passes in Gallio, but fails in nCrunch:

    [TestFixture]
    public class DependsOnTest
    {
        private String _state = "";
        [Test(Order = 0)]
        public void First()
        {
            Assert.AreEqual("", _state);
            _state = "First";
        }

        [Test(Order = 1)]
        [DependsOn("First")]
        public void Second()
        {
            Assert.AreEqual("First", _state);
            _state = "Second";
        }

        [Test(Order = 2)]
        [DependsOn("Second")]
        public void Third()
        {
            Assert.AreEqual("Second", _state);
            _state = "Third";
        }


Is this a known bug? I read in another post that nCrunch uses Gallio under the hood - but looks like it does not behave 100%....
Hi, thanks for posting! I'm glad your enjoying NCrunch!

I can understand why the 'DependsOn' attribute would have some problems. NCrunch separates tests into batches before running them, in order to provide the best experience with parallel execution. It's possible that the tests are being separated from each other into different batches and this is changing the sequence in which they are run.

I'll note this issue down for a future fix. Meanwhile, you may be able to reduce the fragility of the tests by marking the entire fixture with the 'NCrunch.Framework.Isolated' attribute. This will encourage NCrunch to pipeline the tests together and will reduce the risk of them being separated at runtime. You can find more information about this attribute in this wiki at http://wiki.ncrunch.net/IsolatedAttribute.ashx

Post a reply

Log in to reply.