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

Notification

Icon
Error

MSTest - NCrunch doesn't fail on multiple TestInitialize
jamesmanning
#1 Posted : Sunday, May 20, 2012 10:17:43 PM(UTC)
Rank: Member

Groups: Registered
Joined: 5/7/2012(UTC)
Posts: 17
Location: Raleigh, NC

Was thanked: 1 time(s) in 1 post(s)
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:

Code:

using Microsoft.VisualStudio.TestTools.UnitTesting;

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

        [TestInitialize]
        public void TestInit2()
        { }

        [TestMethod]
        public void TestMethod1()
        {
        }
    }
}
Remco
#2 Posted : Sunday, May 20, 2012 11:12:47 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
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
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.025 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download