Last active
January 15, 2016 19:44
-
-
Save miklund/e40b96a56865f0e0c9fa to your computer and use it in GitHub Desktop.
2009-05-30 New ExpectedException model in NUnit 2.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: New ExpectedException model in NUnit 2.5 | |
# Author: Mikael Lundin | |
# Link: http://blog.mikaellundin.name/2009/05/30/new-expectedexception-model-in-nunit-25.html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestMethod] | |
[ExpectedException(typeof(NullReferenceException))] | |
public void NullReferenceExceptionTestInMsTest() | |
{ | |
/* Setup */ | |
string[] names = null; | |
int numberOfNames = 0; | |
/* Test */ | |
numberOfNames = names.Length; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test(Description = "Testing the new ExpectedException functionality in NUnit 2.5")] | |
public void NullReferenceExceptionTest() | |
{ | |
/* Setup */ | |
string[] names = null; | |
int numberOfNames = 0; | |
/* Assert */ | |
Assert.Throws<NullReferenceException>( | |
/* Test */ | |
() => numberOfNames = names.Length); | |
/* Assert that numberOfNames is still zero */ | |
Assert.That(numberOfNames == 0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Test(Description = "Testing the new ExpectedException functionality in NUnit 2.5")] | |
public void NullReferenceExceptionTest() | |
{ | |
/* Setup */ | |
string[] names = null; | |
int numberOfNames = 0; | |
/* Test */ | |
TestDelegate throwingCode = () => numberOfNames = names.Length; | |
/* Assert */ | |
Assert.Throws<NullReferenceException>(throwingCode); | |
/* Assert that numberOfNames is still zero */ | |
Assert.That(numberOfNames == 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment