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

Notification

Icon
Error

NCrunch doesn't handle MSTest cases annotated with ExpectedExceptionBaseAttribute derivations
VNicholson
#1 Posted : Wednesday, May 8, 2024 12:27:08 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 25
Location: New Zealand

Thanks: 6 times
Was thanked: 3 time(s) in 3 post(s)
NCrunch seems to behave differently to the Resharper and MSTest runners when it encounters test methods annotated with ExpectedException annotations.

When the normal ExpectedException annotation is encountered, NCrunch works fine. When an annotation derived from ExpectedExceptionBaseAttribute is encountered however, NCrunch ignores the exception expectation whereas the Resharper and MSTest runners work fine.

A minimal reproduction is shown below.

Code:
[TestClass]
public sealed class ExpectedExceptionTests
{
    [TestMethod]
    [ExpectedException(typeof(InvalidOperationException))]
    public void ExpectedExceptionAttributeTest()
    {
        throw new InvalidOperationException("This is fine");
    }

    [TestMethod]
    [DerivedExpectedExceptionAttribute(typeof(InvalidOperationException))]
    public void ExpectedExceptionDerivedAttributeTest()
    {
        throw new InvalidOperationException("This is fine in Resharper and MSTest, but fails in NCrunch because the derived expected exception annotation is ignored");
    }

    private sealed class DerivedExpectedExceptionAttribute : ExpectedExceptionBaseAttribute
    {
        private readonly Type _expectedExceptionType;

        public DerivedExpectedExceptionAttribute(Type expectedExceptionType)
        {
            _expectedExceptionType = expectedExceptionType;
        }

        protected override void Verify(Exception exception)
        {
            Assert.IsInstanceOfType(exception, _expectedExceptionType);
        }
    }
}

Could NCrunch be updated to support annotations that derive from ExpectedExceptionBaseAnnotation the way the other runners do?
Remco
#2 Posted : Wednesday, May 8, 2024 3:54:38 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing this issue.

Unfortunately, we aren't able to support custom test metadata types under MSTest. This is due to the design of MSTest itself where they've made it very difficult for 3rd party software (like NCrunch) to implement custom behaviour around MSTest types like this one.

NCrunch's MSTest adapter is emulated rather than integrated. Trying to make our features work for MSTest by integrating with all versions of it released over the last 20 years simply wasn't something we were able to do, so we instead have our own adapter that behaves as much like MSTest as we were easily able to implement. Custom exception attributes is one of the areas where the effort required to handle it correctly makes it infeasible for us.
VNicholson
#3 Posted : Wednesday, May 8, 2024 3:56:58 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/19/2013(UTC)
Posts: 25
Location: New Zealand

Thanks: 6 times
Was thanked: 3 time(s) in 3 post(s)
Remco;17324 wrote:
NCrunch's MSTest adapter is emulated rather than integrated. Trying to make our features work for MSTest by integrating with all versions of it released over the last 20 years simply wasn't something we were able to do, so we instead have our own adapter that behaves as much like MSTest as we were easily able to implement. Custom exception attributes is one of the areas where the effort required to handle it correctly makes it infeasible for us.


No worries. I have a workaround so I'll just run with that. ExpectedException is considered pretty meh compared to Assert.ThrowsException these days anyway so I'll just update these legacy tests.
1 user thanked VNicholson for this useful post.
Remco on 5/8/2024(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.031 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download