Build/Test Issues

MSTest - NCrunch doesn't fail on multiple TestInitialize

Started by jamesmanning on 6,728 views

Not sure this is really worth fixing, but in my VS11 Beta, the built-in test runner and the R# tester runner both fail if there are multiple methods marked with TestInitialize:

UTA018: TestClassNameHere.TestMethodNameHere: Cannot define more than one method with the TestInitialize attribute.

NCrunch runs the multiple methods fine, which it would be easy to argue is the better behavior, but I figured I'd mention it here in case there was a goal to 'act' the same (enforcing the same restrictions) as the underlying test framework.

Simple repro case, FWIW:


using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MultipleTestInit
{
    [TestClass]
    public class UnitTest1
    {
        [TestInitialize]
        public void TestInit1()
        {}

        [TestInitialize]
        public void TestInit2()
        { }

        [TestMethod]
        public void TestMethod1()
        {
        }
    }
}
Hi James,

Thanks for reporting this. It's of no surprise to me as NCrunch's test runner only emulates MSTest behaviour rather than integrating with it directly. I expect there will be other similar misalignments, though right now I'd prefer to avoid adding many of these constraints to the NCrunch test runner as some of them are inconsistent and any mistakes on my part could break test behaviour for many people.

One way you could deal with a situation like this (if you wanted to prevent it in your own code) would be to write a test that uses reflection to inspect other test classes for multiple TestInitialize attributes.

Cheers,

Remco

Post a reply

Log in to reply.