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

Notification

Icon
Error

ExpectedException in mstest not being captured when it is marked as async Task.
JoshSim
#1 Posted : Monday, May 13, 2013 5:00:26 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/13/2013(UTC)
Posts: 1

Quote:
[TestMethod]
[ExpectedException(typeof(SomeCustomException))]
public async Task Integration_FailingTest_ThrowsException()
{
await someMethod;
}


The above does not seem to work using NCrunch, it is showing success in my MSTest runner, but not in the nCrunch test runner.

Advice please?

I am evaluating it, and this is the first roadblock today.

Josh
Remco
#2 Posted : Monday, May 13, 2013 11:29:33 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 964 times
Was thanked: 1296 time(s) in 1202 post(s)
Hi Josh,

Thanks for sharing this issue. After a quick test I've concluded that NCrunch's handling of the ExpectedException attribute within MSTest2012 doesn't work correctly with the new async behaviour. I've logged this down to be fixed in the next maintenance release. Meanwhile, I suggest working around the issue by implementing the assertion manually. For example:

Code:
		[TestMethod]
		public async Task Integration_FailingTest_ThrowsException()
		{
			try
			{
				await someMethod;
			}
			catch (Exception ex)
			{
				if (ex is SomeCustomException == false)
					Assert.Fail("Exception thrown was " + ex.InnerException + ", which is not the expected exception");
			}
		}


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.026 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download