source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/IHS BMX Framework/lib/NUnit/NUnit-2.5.10.11092/doc/fixtureSetup.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.5 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 - FixtureSetup</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>TestFixtureSetUpAttribute (NUnit 2.1 / 2.5)</h3>
30
31<p>This attribute is used inside a TestFixture to provide a single set of
32 functions that are performed once prior to executing any of the tests
33 in the fixture.
34
35<p><b>Before NUnit 2.5</b>, a TestFixture could have only one TestFixtureSetUp method
36 and it was required to be an instance method.
37
38<p><b>Beginning with NUnit 2.5</b>, TestFixtureSetUp methods may be either static or
39 instance methods and you may define more than one of them in a fixture.
40 Normally, multiple TestFixtureSetUp methods are only defined at different levels
41 of an inheritance hierarchy, as explained below.
42
43<p>If a TestFixtueSetUp method fails or throws an exception, none of the tests
44 in the fixure are executed and a failure or error is reported.
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 [TestFixtureSetUp] public void Init()
69 { /* ... */ }
70
71 [TestFixtureTearDown] 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;TestFixtureSetUp()&gt; Public Sub Init()
87 ' ...
88 End Sub
89
90 &lt;TestFixtureTearDown()&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 [TestFixtureSetUp] void Init();
111 [TestFixtureTearDown] 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.TestFixtureSetUp() */
134 public void Init()
135 { /* ... */ }
136
137 /** @attribute NUnit.Framework.TestFixtureTearDown() */
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 TestFixtureSetUp attribute is inherited from any base class. Therefore, if a base
152 class has defined a SetFixtureSetUp 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 TestFixtureSetUp method. If you wanted to
156 have some TestFixtureSetUp 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 TestFixtureSetUp method
160 in the base class and another in the derived class. NUnit will call base
161 class TestFixtureSetUp methods before those in the derived classes.
162
163<p><b>Note:</b> Although it is possible to define multiple TestFixtureSetUp 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="teardown.html">TearDownAttribute</a><li><a href="fixtureTeardown.html">TestFixtureTearDownAttribute</a></ul>
171
172</div>
173
174<!-- Submenu -->
175<div id="subnav">
176<ul>
177<li><a href="index.html">NUnit 2.5.10</a></li>
178<ul>
179<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
180<li><a href="assertions.html">Assertions</a></li>
181<li><a href="constraintModel.html">Constraints</a></li>
182<li><a href="attributes.html">Attributes</a></li>
183<ul>
184<li><a href="category.html">Category</a></li>
185<li><a href="combinatorial.html">Combinatorial</a></li>
186<li><a href="culture.html">Culture</a></li>
187<li><a href="datapoint.html">Datapoint(s)</a></li>
188<li><a href="description.html">Description</a></li>
189<li><a href="exception.html">Exception</a></li>
190<li><a href="explicit.html">Explicit</a></li>
191<li><a href="ignore.html">Ignore</a></li>
192<li><a href="maxtime.html">Maxtime</a></li>
193<li><a href="pairwise.html">Pairwise</a></li>
194<li><a href="platform.html">Platform</a></li>
195<li><a href="property.html">Property</a></li>
196<li><a href="random.html">Random</a></li>
197<li><a href="range.html">Range</a></li>
198<li><a href="repeat.html">Repeat</a></li>
199<li><a href="requiredAddin.html">RequiredAddin</a></li>
200<li><a href="requiresMTA.html">Requires&nbsp;MTA</a></li>
201<li><a href="requiresSTA.html">Requires&nbsp;STA</a></li>
202<li><a href="requiresThread.html">Requires&nbsp;Thread</a></li>
203<li><a href="sequential.html">Sequential</a></li>
204<li><a href="setCulture.html">SetCulture</a></li>
205<li><a href="setUICulture.html">SetUICulture</a></li>
206<li><a href="setup.html">Setup</a></li>
207<li><a href="setupFixture.html">SetupFixture</a></li>
208<li><a href="suite.html">Suite</a></li>
209<li><a href="teardown.html">Teardown</a></li>
210<li><a href="test.html">Test</a></li>
211<li><a href="testCase.html">TestCase</a></li>
212<li><a href="testCaseSource.html">TestCaseSource</a></li>
213<li><a href="testFixture.html">TestFixture</a></li>
214<li id="current"><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
215<li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
216<li><a href="theory.html">Theory</a></li>
217<li><a href="timeout.html">Timeout</a></li>
218<li><a href="values.html">Values</a></li>
219<li><a href="valueSource.html">ValueSource</a></li>
220</ul>
221<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
222<li><a href="extensibility.html">Extensibility</a></li>
223<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
224<li><a href="samples.html">Samples</a></li>
225<li><a href="license.html">License</a></li>
226</ul>
227</ul>
228</div>
229<!-- End of Submenu -->
230
231
232<!-- Standard Footer for NUnit.org -->
233<div id="footer">
234 Copyright &copy; 2010 Charlie Poole. All Rights Reserved.
235</div>
236<!-- End of Footer -->
237
238</body>
239</html>
Note: See TracBrowser for help on using the repository browser.