source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/lib/NUnit/NUnit-2.5.10.11092/doc/teardown.html@ 1146

Last change on this file since 1146 was 1146, checked in by Sam Habiel, 13 years ago

Initial Import of BMX4

File size: 7.3 KB
Line 
1<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
2<html>
3<!-- Standard Head Part -->
4<head>
5<title>NUnit - Teardown</title>
6<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
7<meta http-equiv="Content-Language" content="en-US">
8<link rel="stylesheet" type="text/css" href="nunit.css">
9<link rel="shortcut icon" href="favicon.ico">
10</head>
11<!-- End Standard Head Part -->
12
13<body>
14
15<!-- Standard Header for NUnit.org -->
16<div id="header">
17 <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
18 <div id="nav">
19 <a href="http://www.nunit.org">NUnit</a>
20 <a class="active" href="index.html">Documentation</a>
21 </div>
22</div>
23<!-- End of Header -->
24
25<div id="content">
26
27<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->
28
29<h3>TearDownAttribute (NUnit 2.0 / 2.5)</h3>
30
31<p>This attribute is used inside a TestFixture to provide a common set of
32 functions that are performed after each test method is run.
33
34<p><b>Before NUnit 2.5</b>, a TestFixture could have only one TearDown method
35 and it was required to be an instance method.
36
37<p><b>Beginning with NUnit 2.5</b>, TearDown methods may be either static or
38 instance methods and you may define more than one of them in a fixture.
39 Normally, multiple TearDown methods are only defined at different levels
40 of an inheritance hierarchy, as explained below.
41
42<p>So long as any SetUp method runs without error, the TearDown method is
43 guaranteed to run. It will not run if a SetUp method fails or throws an
44 exception.</p>
45
46<h4>Example:</h4>
47
48<div class="code">
49
50<div class="langFilter">
51 <a href="javascript:Show('DD1')" onmouseover="Show('DD1')"><img src="img/langFilter.gif" width="14" height="14" alt="Language Filter"></a>
52 <div id="DD1" class="dropdown" style="display: none" onclick="Hide('DD1')">
53 <a href="javascript:ShowCS()">C#</a><br>
54 <a href="javascript:ShowVB()">VB</a><br>
55 <a href="javascript:ShowMC()">C++</a><br>
56 <a href="javascript:ShowJS()">J#</a><br>
57 </div>
58</div>
59
60<pre class="cs">namespace NUnit.Tests
61{
62 using System;
63 using NUnit.Framework;
64
65 [TestFixture]
66 public class SuccessTests
67 {
68 [SetUp] public void Init()
69 { /* ... */ }
70
71 [TearDown] public void Cleanup()
72 { /* ... */ }
73
74 [Test] public void Add()
75 { /* ... */ }
76 }
77}
78</pre>
79
80<pre class="vb">Imports System
81Imports Nunit.Framework
82
83Namespace Nunit.Tests
84
85 &lt;TestFixture()&gt; Public Class SuccessTests
86 &lt;SetUp()&gt; Public Sub Init()
87 ' ...
88 End Sub
89
90 &lt;TearDown()&gt; Public Sub Cleanup()
91 ' ...
92 End Sub
93
94 &lt;Test()&gt; Public Sub Add()
95 ' ...
96 End Sub
97 End Class
98End Namespace
99</pre>
100
101<pre class="mc">#using &lt;Nunit.Framework.dll&gt;
102using namespace System;
103using namespace NUnit::Framework;
104
105namespace NUnitTests
106{
107 [TestFixture]
108 public __gc class SuccessTests
109 {
110 [SetUp] void Init();
111 [TearDown] void Cleanup();
112
113 [Test] void Add();
114 };
115}
116
117#include "cppsample.h"
118
119namespace NUnitTests {
120 // ...
121}
122</pre>
123
124<pre class="js">package NUnit.Tests;
125
126import System.*;
127import NUnit.Framework.TestFixture;
128
129
130/** @attribute NUnit.Framework.TestFixture() */
131public class SuccessTests
132{
133 /** @attribute NUnit.Framework.SetUp() */
134 public void Init()
135 { /* ... */ }
136
137 /** @attribute NUnit.Framework.TearDown() */
138 public void Cleanup()
139 { /* ... */ }
140
141 /** @attribute NUnit.Framework.Test() */
142 public void Add()
143 { /* ... */ }
144}
145</pre>
146
147</div>
148
149<h3>Inheritance</h3>
150
151<p>The TearDown attribute is inherited from any base class. Therefore, if a base
152 class has defined a TearDown method, that method will be called
153 after each test method in the derived class.
154
155<p>Before NUnit 2.5, you were permitted only one TearDown method. If you wanted to
156 have some TearDown functionality in the base class and add more in the derived
157 class you needed to call the base class method yourself.
158
159<p>With NUnit 2.5, you can achieve the same result by defining a TearDown method
160 in the base class and another in the derived class. NUnit will call base
161 class TearDown methods after those in the derived classes.
162
163<p><b>Note:</b> Although it is possible to define multiple TearDown methods
164 in the same class, you should rarely do so. Unlike methods defined in
165 separate classes in the inheritance hierarchy, the order in which they
166 are executed is not guaranteed.
167
168<h4>See also...</h4>
169<ul>
170<li><a href="setup.html">SetUpAttribute</a><li><a href="fixtureSetup.html">TestFixtureSetUpAttribute</a><li><a href="fixtureTeardown.html">TestFixtureTearDownAttribute</a></ul>
171
172
173</div>
174
175<!-- Submenu -->
176<div id="subnav">
177<ul>
178<li><a href="index.html">NUnit 2.5.10</a></li>
179<ul>
180<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
181<li><a href="assertions.html">Assertions</a></li>
182<li><a href="constraintModel.html">Constraints</a></li>
183<li><a href="attributes.html">Attributes</a></li>
184<ul>
185<li><a href="category.html">Category</a></li>
186<li><a href="combinatorial.html">Combinatorial</a></li>
187<li><a href="culture.html">Culture</a></li>
188<li><a href="datapoint.html">Datapoint(s)</a></li>
189<li><a href="description.html">Description</a></li>
190<li><a href="exception.html">Exception</a></li>
191<li><a href="explicit.html">Explicit</a></li>
192<li><a href="ignore.html">Ignore</a></li>
193<li><a href="maxtime.html">Maxtime</a></li>
194<li><a href="pairwise.html">Pairwise</a></li>
195<li><a href="platform.html">Platform</a></li>
196<li><a href="property.html">Property</a></li>
197<li><a href="random.html">Random</a></li>
198<li><a href="range.html">Range</a></li>
199<li><a href="repeat.html">Repeat</a></li>
200<li><a href="requiredAddin.html">RequiredAddin</a></li>
201<li><a href="requiresMTA.html">Requires&nbsp;MTA</a></li>
202<li><a href="requiresSTA.html">Requires&nbsp;STA</a></li>
203<li><a href="requiresThread.html">Requires&nbsp;Thread</a></li>
204<li><a href="sequential.html">Sequential</a></li>
205<li><a href="setCulture.html">SetCulture</a></li>
206<li><a href="setUICulture.html">SetUICulture</a></li>
207<li><a href="setup.html">Setup</a></li>
208<li><a href="setupFixture.html">SetupFixture</a></li>
209<li><a href="suite.html">Suite</a></li>
210<li id="current"><a href="teardown.html">Teardown</a></li>
211<li><a href="test.html">Test</a></li>
212<li><a href="testCase.html">TestCase</a></li>
213<li><a href="testCaseSource.html">TestCaseSource</a></li>
214<li><a href="testFixture.html">TestFixture</a></li>
215<li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
216<li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
217<li><a href="theory.html">Theory</a></li>
218<li><a href="timeout.html">Timeout</a></li>
219<li><a href="values.html">Values</a></li>
220<li><a href="valueSource.html">ValueSource</a></li>
221</ul>
222<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
223<li><a href="extensibility.html">Extensibility</a></li>
224<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
225<li><a href="samples.html">Samples</a></li>
226<li><a href="license.html">License</a></li>
227</ul>
228</ul>
229</div>
230<!-- End of Submenu -->
231
232
233<!-- Standard Footer for NUnit.org -->
234<div id="footer">
235 Copyright &copy; 2010 Charlie Poole. All Rights Reserved.
236</div>
237<!-- End of Footer -->
238
239</body>
240</html>
Note: See TracBrowser for help on using the repository browser.