2
using System.Reflection;
4
using NUnit.Core.Builders;
6
namespace NUnit.Core.Tests
9
/// Tests of IgnoreException and Assert.Ignore
12
public class IgnoreFixture
15
public void IgnoreThrowsIgnoreException()
17
//Note that we can't use ExpectedException here because
18
//Assert.Ignore takes precedence and the test is ignored.
21
Assert.Ignore("I threw this!");
23
catch(IgnoreException ex)
25
Assert.AreEqual("I threw this!", ex.Message);
30
public void IgnoreWorksForTestCase()
32
Type fixtureType = typeof(IgnoredTestCaseFixture);
33
Test test = TestCaseBuilder.Make( fixtureType, "CallsIgnore" );
34
TestSuite suite = TestFixtureBuilder.Make(fixtureType);
36
TestResult result = test.Run( NullListener.NULL);
37
Assert.IsFalse( result.Executed, "TestCase should not run" );
38
Assert.AreEqual( "Ignore me", result.Message );
42
internal class IgnoredTestCaseFixture
45
public void CallsIgnore()
47
Assert.Ignore("Ignore me");
52
public void IgnoreWorksForTestSuite()
54
//IgnoredTestSuiteFixture testFixture = new IgnoredTestSuiteFixture();
55
TestSuite suite = new TestSuite("IgnoredTestFixture");
56
suite.Add( TestFixtureBuilder.Make( typeof( IgnoredTestSuiteFixture ) ) );
57
TestSuiteResult result = (TestSuiteResult)suite.Run( NullListener.NULL);
59
TestSuiteResult fixtureResult = (TestSuiteResult)result.Results[0];
60
Assert.IsFalse( fixtureResult.Executed, "Fixture should not have been executed" );
62
foreach( TestResult testResult in fixtureResult.Results )
63
Assert.IsFalse( testResult.Executed, "Test case should not have been executed" );
67
internal class IgnoredTestSuiteFixture
70
public void FixtureSetUp()
72
Assert.Ignore("Ignore this fixture");
81
public void AnotherTest()
87
public void IgnoreWorksFromSetUp()
89
TestSuite testFixture = TestFixtureBuilder.Make( typeof( IgnoreInSetUpFixture ) );
90
TestSuiteResult fixtureResult = (TestSuiteResult)testFixture.Run( NullListener.NULL);
92
Assert.IsTrue( fixtureResult.Executed, "Fixture should have been executed" );
94
foreach( TestResult testResult in fixtureResult.Results )
95
Assert.IsFalse( testResult.Executed, "Test case should not have been executed" );
99
internal class IgnoreInSetUpFixture
104
Assert.Ignore( "Ignore this test" );
119
public void IgnoreWithUserMessage()
123
Assert.Ignore( "my message" );
125
catch( IgnoreException ex )
127
Assert.AreEqual( "my message", ex.Message );
132
public void IgnoreWithUserMessage_OneArg()
136
Assert.Ignore( "The number is {0}", 5 );
138
catch( IgnoreException ex )
140
Assert.AreEqual( "The number is 5", ex.Message );
145
public void IgnoreWithUserMessage_ThreeArgs()
149
Assert.Ignore( "The numbers are {0}, {1} and {2}", 1, 2, 3 );
151
catch( IgnoreException ex )
153
Assert.AreEqual( "The numbers are 1, 2 and 3", ex.Message );
158
public void IgnoreWithUserMessage_ArrayOfArgs()
162
Assert.Ignore( "The numbers are {0}, {1} and {2}", new object[] { 1, 2, 3 } );
164
catch( IgnoreException ex )
166
Assert.AreEqual( "The numbers are 1, 2 and 3", ex.Message );