~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/NUnitCore/tests/IgnoreFixture.cs

  • Committer: charliepoole
  • Date: 2006-01-06 01:08:17 UTC
  • Revision ID: vcs-imports@canonical.com-20060106010817-z6xazs4kd89zj8j1
Move core from under NUnitFramework to NUnitCore directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using System;
 
2
using System.Reflection;
 
3
using NUnit.Framework;
 
4
using NUnit.Core.Builders;
 
5
 
 
6
namespace NUnit.Core.Tests
 
7
{
 
8
        /// <summary>
 
9
        /// Tests of IgnoreException and Assert.Ignore
 
10
        /// </summary>
 
11
        [TestFixture]
 
12
        public class IgnoreFixture
 
13
        {
 
14
                [Test]
 
15
                public void IgnoreThrowsIgnoreException()
 
16
                {
 
17
                        //Note that we can't use ExpectedException here because
 
18
                        //Assert.Ignore takes precedence and the test is ignored.
 
19
                        try
 
20
                        {
 
21
                                Assert.Ignore("I threw this!");
 
22
                        }
 
23
                        catch(IgnoreException ex)
 
24
                        {
 
25
                                Assert.AreEqual("I threw this!", ex.Message);
 
26
                        }
 
27
                }
 
28
 
 
29
                [Test]
 
30
                public void IgnoreWorksForTestCase()
 
31
                {
 
32
                        Type fixtureType = typeof(IgnoredTestCaseFixture);
 
33
                        Test test = TestCaseBuilder.Make( fixtureType, "CallsIgnore" );
 
34
                        TestSuite suite = TestFixtureBuilder.Make(fixtureType);
 
35
                        suite.Add(test);
 
36
                        TestResult result = test.Run( NullListener.NULL);
 
37
                        Assert.IsFalse( result.Executed, "TestCase should not run" );
 
38
                        Assert.AreEqual( "Ignore me", result.Message );
 
39
                }
 
40
 
 
41
                [TestFixture]
 
42
                internal class IgnoredTestCaseFixture
 
43
                {
 
44
                        [Test]
 
45
                        public void CallsIgnore()
 
46
                        {
 
47
                                Assert.Ignore("Ignore me");
 
48
                        }
 
49
                }
 
50
 
 
51
                [Test]
 
52
                public void IgnoreWorksForTestSuite()
 
53
                {
 
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);
 
58
 
 
59
                        TestSuiteResult fixtureResult = (TestSuiteResult)result.Results[0];
 
60
                        Assert.IsFalse( fixtureResult.Executed, "Fixture should not have been executed" );
 
61
                        
 
62
                        foreach( TestResult testResult in fixtureResult.Results )
 
63
                                Assert.IsFalse( testResult.Executed, "Test case should not have been executed" );
 
64
                }
 
65
 
 
66
                [TestFixture]
 
67
                internal class IgnoredTestSuiteFixture
 
68
                {
 
69
                        [TestFixtureSetUp]
 
70
                        public void FixtureSetUp()
 
71
                        {
 
72
                                Assert.Ignore("Ignore this fixture");
 
73
                        }
 
74
 
 
75
                        [Test]
 
76
                        public void ATest()
 
77
                        {
 
78
                        }
 
79
 
 
80
                        [Test]
 
81
                        public void AnotherTest()
 
82
                        {
 
83
                        }
 
84
                }
 
85
 
 
86
                [Test]
 
87
                public void IgnoreWorksFromSetUp()
 
88
                {
 
89
                        TestSuite testFixture = TestFixtureBuilder.Make( typeof( IgnoreInSetUpFixture ) );
 
90
                        TestSuiteResult fixtureResult = (TestSuiteResult)testFixture.Run( NullListener.NULL);
 
91
 
 
92
                        Assert.IsTrue( fixtureResult.Executed, "Fixture should have been executed" );
 
93
                        
 
94
                        foreach( TestResult testResult in fixtureResult.Results )
 
95
                                Assert.IsFalse( testResult.Executed, "Test case should not have been executed" );
 
96
                }
 
97
 
 
98
                [TestFixture]
 
99
                internal class IgnoreInSetUpFixture
 
100
                {
 
101
                        [SetUp]
 
102
                        public void SetUp()
 
103
                        {
 
104
                                Assert.Ignore( "Ignore this test" );
 
105
                        }
 
106
 
 
107
                        [Test]
 
108
                        public void Test1()
 
109
                        {
 
110
                        }
 
111
 
 
112
                        [Test]
 
113
                        public void Test2()
 
114
                        {
 
115
                        }
 
116
                }
 
117
 
 
118
                [Test]
 
119
                public void IgnoreWithUserMessage()
 
120
                {
 
121
                        try
 
122
                        {
 
123
                                Assert.Ignore( "my message" );
 
124
                        }
 
125
                        catch( IgnoreException ex )
 
126
                        {
 
127
                                Assert.AreEqual( "my message", ex.Message );
 
128
                        }
 
129
                }
 
130
 
 
131
                [Test]
 
132
                public void IgnoreWithUserMessage_OneArg()
 
133
                {
 
134
                        try
 
135
                        {
 
136
                                Assert.Ignore( "The number is {0}", 5 );
 
137
                        }
 
138
                        catch( IgnoreException ex )
 
139
                        {
 
140
                                Assert.AreEqual( "The number is 5", ex.Message );
 
141
                        }
 
142
                }
 
143
 
 
144
                [Test]
 
145
                public void IgnoreWithUserMessage_ThreeArgs()
 
146
                {
 
147
                        try
 
148
                        {
 
149
                                Assert.Ignore( "The numbers are {0}, {1} and {2}", 1, 2, 3 );
 
150
                        }
 
151
                        catch( IgnoreException ex )
 
152
                        {
 
153
                                Assert.AreEqual( "The numbers are 1, 2 and 3", ex.Message );
 
154
                        }
 
155
                }
 
156
 
 
157
                [Test]
 
158
                public void IgnoreWithUserMessage_ArrayOfArgs()
 
159
                {
 
160
                        try
 
161
                        {
 
162
                        Assert.Ignore( "The numbers are {0}, {1} and {2}", new object[] { 1, 2, 3 } );
 
163
                        }
 
164
                        catch( IgnoreException ex )
 
165
                        {
 
166
                                Assert.AreEqual( "The numbers are 1, 2 and 3", ex.Message );
 
167
                        }
 
168
                }
 
169
        }
 
170
}