~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/tests/test-assembly/FixtureSetUpTearDownTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ****************************************************************
2
 
// Copyright 2007, Charlie Poole
3
 
// This is free software licensed under the NUnit license. You may
4
 
// obtain a copy of the license at http://nunit.org
5
 
// ****************************************************************
6
 
 
7
 
using System;
8
 
using NUnit.Framework;
9
 
 
10
 
namespace NUnit.TestData.FixtureSetUpTearDown
11
 
{
12
 
    [TestFixture]
13
 
    public class SetUpAndTearDownFixture
14
 
    {
15
 
        public int setUpCount = 0;
16
 
        public int tearDownCount = 0;
17
 
 
18
 
        [TestFixtureSetUp]
19
 
        public virtual void Init()
20
 
        {
21
 
            setUpCount++;
22
 
        }
23
 
 
24
 
        [TestFixtureTearDown]
25
 
        public virtual void Destroy()
26
 
        {
27
 
            tearDownCount++;
28
 
        }
29
 
 
30
 
        [Test]
31
 
        public void Success() { }
32
 
 
33
 
        [Test]
34
 
        public void EvenMoreSuccess() { }
35
 
    }
36
 
 
37
 
    [TestFixture, Explicit]
38
 
        public class ExplicitSetUpAndTearDownFixture
39
 
        {
40
 
                public int setUpCount = 0;
41
 
                public int tearDownCount = 0;
42
 
 
43
 
                [TestFixtureSetUp]
44
 
                public virtual void Init()
45
 
                {
46
 
                        setUpCount++;
47
 
                }
48
 
 
49
 
                [TestFixtureTearDown]
50
 
                public virtual void Destroy()
51
 
                {
52
 
                        tearDownCount++;
53
 
                }
54
 
 
55
 
                [Test]
56
 
                public void Success(){}
57
 
 
58
 
                [Test]
59
 
                public void EvenMoreSuccess(){}
60
 
        }
61
 
 
62
 
        [TestFixture]
63
 
        public class InheritSetUpAndTearDown : SetUpAndTearDownFixture
64
 
        {
65
 
                [Test]
66
 
                public void AnotherTest(){}
67
 
 
68
 
                [Test]
69
 
                public void YetAnotherTest(){}
70
 
        }
71
 
 
72
 
        [TestFixture]
73
 
        public class DefineInheritSetUpAndTearDown : SetUpAndTearDownFixture
74
 
        {
75
 
        public int derivedSetUpCount;
76
 
        public int derivedTearDownCount;
77
 
 
78
 
        [TestFixtureSetUp]
79
 
        public override void Init()
80
 
        {
81
 
            derivedSetUpCount++;
82
 
        }
83
 
 
84
 
        [TestFixtureTearDown]
85
 
        public override void Destroy()
86
 
        {
87
 
            derivedTearDownCount++;
88
 
        }
89
 
 
90
 
        [Test]
91
 
        public void AnotherTest() { }
92
 
 
93
 
        [Test]
94
 
        public void YetAnotherTest() { }
95
 
    }
96
 
 
97
 
    [TestFixture]
98
 
    public class DerivedSetUpAndTearDownFixture : SetUpAndTearDownFixture
99
 
    {
100
 
        public int derivedSetUpCount;
101
 
        public int derivedTearDownCount;
102
 
 
103
 
        public bool baseSetUpCalledFirst;
104
 
        public bool baseTearDownCalledLast;
105
 
 
106
 
        [TestFixtureSetUp]
107
 
        public void Init2()
108
 
        {
109
 
            derivedSetUpCount++;
110
 
            baseSetUpCalledFirst = this.setUpCount > 0;
111
 
        }
112
 
 
113
 
        [TestFixtureTearDown]
114
 
        public void Destroy2()
115
 
        {
116
 
            derivedTearDownCount++;
117
 
            baseTearDownCalledLast = this.tearDownCount == 0;
118
 
        }
119
 
 
120
 
        [Test]
121
 
        public void AnotherTest() { }
122
 
 
123
 
        [Test]
124
 
        public void YetAnotherTest() { }
125
 
    }
126
 
 
127
 
    [TestFixture]
128
 
    public class StaticSetUpAndTearDownFixture
129
 
    {
130
 
        public static int setUpCount = 0;
131
 
        public static int tearDownCount = 0;
132
 
 
133
 
        [TestFixtureSetUp]
134
 
        public static void Init()
135
 
        {
136
 
            setUpCount++;
137
 
        }
138
 
 
139
 
        [TestFixtureTearDown]
140
 
        public static void Destroy()
141
 
        {
142
 
            tearDownCount++;
143
 
        }
144
 
    }
145
 
 
146
 
    [TestFixture]
147
 
    public class DerivedStaticSetUpAndTearDownFixture : StaticSetUpAndTearDownFixture
148
 
    {
149
 
        public static int derivedSetUpCount;
150
 
        public static int derivedTearDownCount;
151
 
 
152
 
        public static bool baseSetUpCalledFirst;
153
 
        public static bool baseTearDownCalledLast;
154
 
 
155
 
 
156
 
        [TestFixtureSetUp]
157
 
        public static void Init2()
158
 
        {
159
 
            derivedSetUpCount++;
160
 
            baseSetUpCalledFirst = setUpCount > 0;
161
 
        }
162
 
 
163
 
        [TestFixtureTearDown]
164
 
        public static void Destroy2()
165
 
        {
166
 
            derivedTearDownCount++;
167
 
            baseTearDownCalledLast = tearDownCount == 0;
168
 
        }
169
 
    }
170
 
 
171
 
#if CLR_2_0 || CLR_4_0
172
 
    [TestFixture]
173
 
    public static class StaticClassSetUpAndTearDownFixture
174
 
    {
175
 
        public static int setUpCount = 0;
176
 
        public static int tearDownCount = 0;
177
 
 
178
 
        [TestFixtureSetUp]
179
 
        public static void Init()
180
 
        {
181
 
            setUpCount++;
182
 
        }
183
 
 
184
 
        [TestFixtureTearDown]
185
 
        public static void Destroy()
186
 
        {
187
 
            tearDownCount++;
188
 
        }
189
 
    }
190
 
#endif
191
 
    
192
 
    [TestFixture]
193
 
        public class MisbehavingFixture 
194
 
        {
195
 
                public bool blowUpInSetUp = false;
196
 
                public bool blowUpInTearDown = false;
197
 
 
198
 
                public int setUpCount = 0;
199
 
                public int tearDownCount = 0;
200
 
 
201
 
                public void Reinitialize()
202
 
                {
203
 
                        setUpCount = 0;
204
 
                        tearDownCount = 0;
205
 
 
206
 
                        blowUpInSetUp = false;
207
 
                        blowUpInTearDown = false;
208
 
                }
209
 
 
210
 
                [TestFixtureSetUp]
211
 
                public void BlowUpInSetUp() 
212
 
                {
213
 
                        setUpCount++;
214
 
                        if (blowUpInSetUp)
215
 
                                throw new Exception("This was thrown from fixture setup");
216
 
                }
217
 
 
218
 
                [TestFixtureTearDown]
219
 
                public void BlowUpInTearDown()
220
 
                {
221
 
                        tearDownCount++;
222
 
                        if ( blowUpInTearDown )
223
 
                                throw new Exception("This was thrown from fixture teardown");
224
 
                }
225
 
 
226
 
                [Test]
227
 
                public void nothingToTest() 
228
 
                {
229
 
                }
230
 
        }
231
 
 
232
 
        [TestFixture]
233
 
        public class ExceptionInConstructor
234
 
        {
235
 
                public ExceptionInConstructor()
236
 
                {
237
 
                        throw new Exception( "This was thrown in constructor" );
238
 
                }
239
 
 
240
 
                [Test]
241
 
                public void nothingToTest()
242
 
                {
243
 
                }
244
 
        }
245
 
 
246
 
        [TestFixture]
247
 
        public class IgnoreInFixtureSetUp
248
 
        {
249
 
                [TestFixtureSetUp]
250
 
                public void SetUpCallsIgnore() 
251
 
                {
252
 
                        Assert.Ignore( "TestFixtureSetUp called Ignore" );
253
 
                }
254
 
 
255
 
                [Test]
256
 
                public void nothingToTest() 
257
 
                {
258
 
                }
259
 
        }
260
 
 
261
 
        [TestFixture]
262
 
        public class SetUpAndTearDownWithTestInName
263
 
        {
264
 
                public int setUpCount = 0;
265
 
                public int tearDownCount = 0;
266
 
 
267
 
                [TestFixtureSetUp]
268
 
                public virtual void TestFixtureSetUp()
269
 
                {
270
 
                        setUpCount++;
271
 
                }
272
 
 
273
 
                [TestFixtureTearDown]
274
 
                public virtual void TestFixtureTearDown()
275
 
                {
276
 
                        tearDownCount++;
277
 
                }
278
 
 
279
 
                [Test]
280
 
                public void Success(){}
281
 
 
282
 
                [Test]
283
 
                public void EvenMoreSuccess(){}
284
 
        }
285
 
 
286
 
        [TestFixture, Ignore( "Do Not Run This" )]
287
 
        public class IgnoredFixture
288
 
        {
289
 
                public bool setupCalled = false;
290
 
                public bool teardownCalled = false;
291
 
 
292
 
                [TestFixtureSetUp]
293
 
                public virtual void ShouldNotRun()
294
 
                {
295
 
                        setupCalled = true;
296
 
                }
297
 
 
298
 
                [TestFixtureTearDown]
299
 
                public virtual void NeitherShouldThis()
300
 
                {
301
 
                        teardownCalled = true;
302
 
                }
303
 
 
304
 
                [Test]
305
 
                public void Success(){}
306
 
 
307
 
                [Test]
308
 
                public void EvenMoreSuccess(){}
309
 
        }
310
 
 
311
 
        [TestFixture]
312
 
        public class FixtureWithNoTests
313
 
        {
314
 
                public bool setupCalled = false;
315
 
                public bool teardownCalled = false;
316
 
 
317
 
                [TestFixtureSetUp]
318
 
                public virtual void Init()
319
 
                {
320
 
                        setupCalled = true;
321
 
                }
322
 
 
323
 
                [TestFixtureTearDown]
324
 
                public virtual void Destroy()
325
 
                {
326
 
                        teardownCalled = true;
327
 
                }
328
 
        }
329
 
 
330
 
    [TestFixture]
331
 
    public class DisposableFixture : IDisposable
332
 
    {
333
 
        public bool disposeCalled = false;
334
 
 
335
 
        [Test]
336
 
        public void OneTest() { }
337
 
 
338
 
        public void Dispose()
339
 
        {
340
 
            disposeCalled = true;
341
 
        }
342
 
    }
343
 
}
 
1
// ****************************************************************
 
2
// Copyright 2007, Charlie Poole
 
3
// This is free software licensed under the NUnit license. You may
 
4
// obtain a copy of the license at http://nunit.org
 
5
// ****************************************************************
 
6
 
 
7
using System;
 
8
using NUnit.Framework;
 
9
 
 
10
namespace NUnit.TestData.FixtureSetUpTearDown
 
11
{
 
12
    [TestFixture]
 
13
    public class SetUpAndTearDownFixture
 
14
    {
 
15
        public int setUpCount = 0;
 
16
        public int tearDownCount = 0;
 
17
 
 
18
        [TestFixtureSetUp]
 
19
        public virtual void Init()
 
20
        {
 
21
            setUpCount++;
 
22
        }
 
23
 
 
24
        [TestFixtureTearDown]
 
25
        public virtual void Destroy()
 
26
        {
 
27
            tearDownCount++;
 
28
        }
 
29
 
 
30
        [Test]
 
31
        public void Success() { }
 
32
 
 
33
        [Test]
 
34
        public void EvenMoreSuccess() { }
 
35
    }
 
36
 
 
37
    [TestFixture, Explicit]
 
38
        public class ExplicitSetUpAndTearDownFixture
 
39
        {
 
40
                public int setUpCount = 0;
 
41
                public int tearDownCount = 0;
 
42
 
 
43
                [TestFixtureSetUp]
 
44
                public virtual void Init()
 
45
                {
 
46
                        setUpCount++;
 
47
                }
 
48
 
 
49
                [TestFixtureTearDown]
 
50
                public virtual void Destroy()
 
51
                {
 
52
                        tearDownCount++;
 
53
                }
 
54
 
 
55
                [Test]
 
56
                public void Success(){}
 
57
 
 
58
                [Test]
 
59
                public void EvenMoreSuccess(){}
 
60
        }
 
61
 
 
62
        [TestFixture]
 
63
        public class InheritSetUpAndTearDown : SetUpAndTearDownFixture
 
64
        {
 
65
                [Test]
 
66
                public void AnotherTest(){}
 
67
 
 
68
                [Test]
 
69
                public void YetAnotherTest(){}
 
70
        }
 
71
 
 
72
        [TestFixture]
 
73
        public class DefineInheritSetUpAndTearDown : SetUpAndTearDownFixture
 
74
        {
 
75
        public int derivedSetUpCount;
 
76
        public int derivedTearDownCount;
 
77
 
 
78
        [TestFixtureSetUp]
 
79
        public override void Init()
 
80
        {
 
81
            derivedSetUpCount++;
 
82
        }
 
83
 
 
84
        [TestFixtureTearDown]
 
85
        public override void Destroy()
 
86
        {
 
87
            derivedTearDownCount++;
 
88
        }
 
89
 
 
90
        [Test]
 
91
        public void AnotherTest() { }
 
92
 
 
93
        [Test]
 
94
        public void YetAnotherTest() { }
 
95
    }
 
96
 
 
97
    [TestFixture]
 
98
    public class DerivedSetUpAndTearDownFixture : SetUpAndTearDownFixture
 
99
    {
 
100
        public int derivedSetUpCount;
 
101
        public int derivedTearDownCount;
 
102
 
 
103
        public bool baseSetUpCalledFirst;
 
104
        public bool baseTearDownCalledLast;
 
105
 
 
106
        [TestFixtureSetUp]
 
107
        public void Init2()
 
108
        {
 
109
            derivedSetUpCount++;
 
110
            baseSetUpCalledFirst = this.setUpCount > 0;
 
111
        }
 
112
 
 
113
        [TestFixtureTearDown]
 
114
        public void Destroy2()
 
115
        {
 
116
            derivedTearDownCount++;
 
117
            baseTearDownCalledLast = this.tearDownCount == 0;
 
118
        }
 
119
 
 
120
        [Test]
 
121
        public void AnotherTest() { }
 
122
 
 
123
        [Test]
 
124
        public void YetAnotherTest() { }
 
125
    }
 
126
 
 
127
    [TestFixture]
 
128
    public class StaticSetUpAndTearDownFixture
 
129
    {
 
130
        public static int setUpCount = 0;
 
131
        public static int tearDownCount = 0;
 
132
 
 
133
        [TestFixtureSetUp]
 
134
        public static void Init()
 
135
        {
 
136
            setUpCount++;
 
137
        }
 
138
 
 
139
        [TestFixtureTearDown]
 
140
        public static void Destroy()
 
141
        {
 
142
            tearDownCount++;
 
143
        }
 
144
    }
 
145
 
 
146
    [TestFixture]
 
147
    public class DerivedStaticSetUpAndTearDownFixture : StaticSetUpAndTearDownFixture
 
148
    {
 
149
        public static int derivedSetUpCount;
 
150
        public static int derivedTearDownCount;
 
151
 
 
152
        public static bool baseSetUpCalledFirst;
 
153
        public static bool baseTearDownCalledLast;
 
154
 
 
155
 
 
156
        [TestFixtureSetUp]
 
157
        public static void Init2()
 
158
        {
 
159
            derivedSetUpCount++;
 
160
            baseSetUpCalledFirst = setUpCount > 0;
 
161
        }
 
162
 
 
163
        [TestFixtureTearDown]
 
164
        public static void Destroy2()
 
165
        {
 
166
            derivedTearDownCount++;
 
167
            baseTearDownCalledLast = tearDownCount == 0;
 
168
        }
 
169
    }
 
170
 
 
171
#if CLR_2_0 || CLR_4_0
 
172
    [TestFixture]
 
173
    public static class StaticClassSetUpAndTearDownFixture
 
174
    {
 
175
        public static int setUpCount = 0;
 
176
        public static int tearDownCount = 0;
 
177
 
 
178
        [TestFixtureSetUp]
 
179
        public static void Init()
 
180
        {
 
181
            setUpCount++;
 
182
        }
 
183
 
 
184
        [TestFixtureTearDown]
 
185
        public static void Destroy()
 
186
        {
 
187
            tearDownCount++;
 
188
        }
 
189
    }
 
190
#endif
 
191
    
 
192
    [TestFixture]
 
193
        public class MisbehavingFixture 
 
194
        {
 
195
                public bool blowUpInSetUp = false;
 
196
                public bool blowUpInTearDown = false;
 
197
 
 
198
                public int setUpCount = 0;
 
199
                public int tearDownCount = 0;
 
200
 
 
201
                public void Reinitialize()
 
202
                {
 
203
                        setUpCount = 0;
 
204
                        tearDownCount = 0;
 
205
 
 
206
                        blowUpInSetUp = false;
 
207
                        blowUpInTearDown = false;
 
208
                }
 
209
 
 
210
                [TestFixtureSetUp]
 
211
                public void BlowUpInSetUp() 
 
212
                {
 
213
                        setUpCount++;
 
214
                        if (blowUpInSetUp)
 
215
                                throw new Exception("This was thrown from fixture setup");
 
216
                }
 
217
 
 
218
                [TestFixtureTearDown]
 
219
                public void BlowUpInTearDown()
 
220
                {
 
221
                        tearDownCount++;
 
222
                        if ( blowUpInTearDown )
 
223
                                throw new Exception("This was thrown from fixture teardown");
 
224
                }
 
225
 
 
226
                [Test]
 
227
                public void nothingToTest() 
 
228
                {
 
229
                }
 
230
        }
 
231
 
 
232
        [TestFixture]
 
233
        public class ExceptionInConstructor
 
234
        {
 
235
                public ExceptionInConstructor()
 
236
                {
 
237
                        throw new Exception( "This was thrown in constructor" );
 
238
                }
 
239
 
 
240
                [Test]
 
241
                public void nothingToTest()
 
242
                {
 
243
                }
 
244
        }
 
245
 
 
246
        [TestFixture]
 
247
        public class IgnoreInFixtureSetUp
 
248
        {
 
249
                [TestFixtureSetUp]
 
250
                public void SetUpCallsIgnore() 
 
251
                {
 
252
                        Assert.Ignore( "TestFixtureSetUp called Ignore" );
 
253
                }
 
254
 
 
255
                [Test]
 
256
                public void nothingToTest() 
 
257
                {
 
258
                }
 
259
        }
 
260
 
 
261
        [TestFixture]
 
262
        public class SetUpAndTearDownWithTestInName
 
263
        {
 
264
                public int setUpCount = 0;
 
265
                public int tearDownCount = 0;
 
266
 
 
267
                [TestFixtureSetUp]
 
268
                public virtual void TestFixtureSetUp()
 
269
                {
 
270
                        setUpCount++;
 
271
                }
 
272
 
 
273
                [TestFixtureTearDown]
 
274
                public virtual void TestFixtureTearDown()
 
275
                {
 
276
                        tearDownCount++;
 
277
                }
 
278
 
 
279
                [Test]
 
280
                public void Success(){}
 
281
 
 
282
                [Test]
 
283
                public void EvenMoreSuccess(){}
 
284
        }
 
285
 
 
286
        [TestFixture, Ignore( "Do Not Run This" )]
 
287
        public class IgnoredFixture
 
288
        {
 
289
                public bool setupCalled = false;
 
290
                public bool teardownCalled = false;
 
291
 
 
292
                [TestFixtureSetUp]
 
293
                public virtual void ShouldNotRun()
 
294
                {
 
295
                        setupCalled = true;
 
296
                }
 
297
 
 
298
                [TestFixtureTearDown]
 
299
                public virtual void NeitherShouldThis()
 
300
                {
 
301
                        teardownCalled = true;
 
302
                }
 
303
 
 
304
                [Test]
 
305
                public void Success(){}
 
306
 
 
307
                [Test]
 
308
                public void EvenMoreSuccess(){}
 
309
        }
 
310
 
 
311
        [TestFixture]
 
312
        public class FixtureWithNoTests
 
313
        {
 
314
                public bool setupCalled = false;
 
315
                public bool teardownCalled = false;
 
316
 
 
317
                [TestFixtureSetUp]
 
318
                public virtual void Init()
 
319
                {
 
320
                        setupCalled = true;
 
321
                }
 
322
 
 
323
                [TestFixtureTearDown]
 
324
                public virtual void Destroy()
 
325
                {
 
326
                        teardownCalled = true;
 
327
                }
 
328
        }
 
329
 
 
330
    [TestFixture]
 
331
    public class DisposableFixture : IDisposable
 
332
    {
 
333
        public bool disposeCalled = false;
 
334
 
 
335
        [Test]
 
336
        public void OneTest() { }
 
337
 
 
338
        public void Dispose()
 
339
        {
 
340
            disposeCalled = true;
 
341
        }
 
342
    }
 
343
}