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

Notification

Icon
Error

Tests with custom ExpectedException attribute are failing
Vlad
#1 Posted : Saturday, June 30, 2012 4:50:50 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/30/2012(UTC)
Posts: 2

Hello,

We tried to use NCrunch on our project and found that all our tests that use custom expected exception attribute fail in NCrunch. They succeed in MSTest just fine.

Here is test code:
Code:

[TestMethod]
[ExpectedMissingInputException()]
public void ExecuteTaskThrowsIfInputIsNull()
{
    CallMyMethod(null);
}

...
void CallMyMethod(string str)
{
    if (str==null) throw ArgumentNullException( "str");
}

where ExpectedMissingInputException attribute is defined like this:
Code:

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ExpectedMissingInputExceptionAttribute : ExpectedExceptionBaseAttribute
{
  public ExpectedMissingInputExceptionAttribute() {}

  protected override void Verify(Exception exception)
  {
    if (!(exception is ArgumentNullException))
    {
      throw new ArgumentException("ArgumentNullException is expected, but actual exception was {0}", exception.GetType().FullName);
    }
  }
}


Is it NCrunch limitation or something should be configured in our NCrunch workspace?
Remco
#2 Posted : Monday, July 2, 2012 3:56:31 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Vlad,

Thanks for posting!

NCrunch uses its own custom-built test runner to execute MSTest tests, and at the moment this test runner does not support custom ExpectedException attributes. Where working with tests that require this behaviour in NCrunch, I recommend introducing the exception filter logic in the test itself, perhaps delegating it to a reusable block of code if you have many tests that do this.

Cheers,

Remco
Vlad
#3 Posted : Monday, July 2, 2012 12:55:02 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/30/2012(UTC)
Posts: 2

Remco;2314 wrote:
NCrunch uses its own custom-built test runner to execute MSTest tests, and at the moment this test runner does not support custom ExpectedException attributes. Where working with tests that require this behaviour in NCrunch, I recommend introducing the exception filter logic in the test itself, perhaps delegating it to a reusable block of code if you have many tests that do this.

We have a lot of tests like this (hindreds+) and changing all of them will be hard to justify. Using custom attribute makes test code cleaner and more readable, at least our team prefer it like this.
Do you know if there are plans to start supporting custom ExpectedException in the nearest releases of NCrunch?
Remco
#4 Posted : Tuesday, July 3, 2012 8:42:41 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Sorry, but right now it doesn't look likely that support for custom ExpectedException attributes will be added in the near future. Very few users make use of these, and the effort required to reliably implement them is considerable (they are very tightly integrated in the MSTest framework). I wish I could give you a better solution, but I'm afraid I can't.
NickApps
#5 Posted : Sunday, November 1, 2015 5:00:10 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/1/2015(UTC)
Posts: 1
Location: United Kingdom

Has this issue ever been addressed?
Remco
#6 Posted : Sunday, November 1, 2015 9:05:31 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Sorry, it does not look custom MSTest ExpectedException attributes will ever be supported by NCrunch.
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.047 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download