1
<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
3
<!-- Standard Head Part -->
5
<title>NUnit - Setup</title>
6
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
7
<meta http-equiv="Content-Language" content="en-US">
8
<meta name="norton-safeweb-site-verification" content="tb6xj01p4hgo5x-8wscsmq633y11-e6nhk-bnb5d987bseanyp6p0uew-pec8j963qlzj32k5x9h3r2q7wh-vmy8bbhek5lnpp5w4p8hocouuq39e09jrkihdtaeknua" />
9
<link rel="stylesheet" type="text/css" href="nunit.css">
10
<link rel="shortcut icon" href="favicon.ico">
12
<!-- End Standard Head Part -->
16
<!-- Standard Header for NUnit.org -->
18
<a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
1
<!-- saved from url=(0014)about:internet --><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
3
<!-- Standard Head Part -->
5
<title>NUnit - Setup</title>
6
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
7
<meta http-equiv="Content-Language" content="en-US">
8
<meta name="norton-safeweb-site-verification" content="tb6xj01p4hgo5x-8wscsmq633y11-e6nhk-bnb5d987bseanyp6p0uew-pec8j963qlzj32k5x9h3r2q7wh-vmy8bbhek5lnpp5w4p8hocouuq39e09jrkihdtaeknua" />
9
<link rel="stylesheet" type="text/css" href="nunit.css">
10
<link rel="shortcut icon" href="favicon.ico">
12
<!-- End Standard Head Part -->
16
<!-- Standard Header for NUnit.org -->
18
<a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
20
20
<a href="http://www.nunit.org">NUnit</a>
21
21
<a class="active" href="index.html">Documentation</a>
24
<!-- End of Header -->
28
<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->
30
<h3>SetUpAttribute (NUnit 2.0 / 2.5)</h3>
32
<p>This attribute is used inside a TestFixture to provide a common set of
33
functions that are performed just before each test method is called.
35
<p><b>Before NUnit 2.5</b>, a TestFixture could have only one SetUp method
36
and it was required to be an instance method.
38
<p><b>Beginning with NUnit 2.5</b>, SetUp methods may be either static or
39
instance methods and you may define more than one of them in a fixture.
40
Normally, multiple SetUp methods are only defined at different levels
41
of an inheritance hierarchy, as explained below.
43
<p>If a SetUp method fails or throws an exception, the test is not executed
44
and a failure or error is reported.
51
<div class="langFilter">
52
<a href="javascript:Show('DD1')" onmouseover="Show('DD1')"><img src="img/langFilter.gif" width="14" height="14" alt="Language Filter"></a>
53
<div id="DD1" class="dropdown" style="display: none" onclick="Hide('DD1')">
54
<a href="javascript:ShowCS()">C#</a><br>
55
<a href="javascript:ShowVB()">VB</a><br>
56
<a href="javascript:ShowMC()">C++</a><br>
57
<a href="javascript:ShowJS()">J#</a><br>
61
<pre class="cs">namespace NUnit.Tests
64
using NUnit.Framework;
67
public class SuccessTests
69
[SetUp] public void Init()
72
[TearDown] public void Cleanup()
75
[Test] public void Add()
81
<pre class="vb">Imports System
82
Imports Nunit.Framework
86
<TestFixture()> Public Class SuccessTests
87
<SetUp()> Public Sub Init()
91
<TearDown()> Public Sub Cleanup()
95
<Test()> Public Sub Add()
102
<pre class="mc">#using <Nunit.Framework.dll>
103
using namespace System;
104
using namespace NUnit::Framework;
109
public __gc class SuccessTests
112
[TearDown] void Cleanup();
118
#include "cppsample.h"
120
namespace NUnitTests {
125
<pre class="js">package NUnit.Tests;
128
import NUnit.Framework.TestFixture;
131
/** @attribute NUnit.Framework.TestFixture() */
132
public class SuccessTests
134
/** @attribute NUnit.Framework.SetUp() */
138
/** @attribute NUnit.Framework.TearDown() */
139
public void Cleanup()
142
/** @attribute NUnit.Framework.Test() */
152
<p>The SetUp attribute is inherited from any base class. Therefore, if a base
153
class has defined a SetUp method, that method will be called
154
before each test method in the derived class.
156
<p>Before NUnit 2.5, you were permitted only one SetUp method. If you wanted to
157
have some SetUp functionality in the base class and add more in the derived
158
class you needed to call the base class method yourself.
160
<p>With NUnit 2.5, you can achieve the same result by defining a SetUp method
161
in the base class and another in the derived class. NUnit will call base
162
class SetUp methods before those in the derived classes.
164
<p><b>Note:</b> Although it is possible to define multiple SetUp methods
165
in the same class, you should rarely do so. Unlike methods defined in
166
separate classes in the inheritance hierarchy, the order in which they
167
are executed is not guaranteed.
171
<li><a href="teardown.html">TearDownAttribute</a><li><a href="fixtureSetup.html">TestFixtureSetUpAttribute</a><li><a href="fixtureTeardown.html">TestFixtureTearDownAttribute</a></ul>
179
<li><a href="index.html">NUnit 2.6</a></li>
181
<li><a href="getStarted.html">Getting Started</a></li>
182
<li><a href="writingTests.html">Writing Tests</a></li>
184
<li><a href="assertions.html">Assertions</a></li>
185
<li><a href="attributes.html">Attributes</a></li>
187
<li><a href="actionAttributes.html">Action Attributes</a></li>
188
<li><a href="category.html">Category</a></li>
189
<li><a href="combinatorial.html">Combinatorial</a></li>
190
<li><a href="culture.html">Culture</a></li>
191
<li><a href="datapoint.html">Datapoint(s)</a></li>
192
<li><a href="description.html">Description</a></li>
193
<li><a href="exception.html">Exception</a></li>
194
<li><a href="explicit.html">Explicit</a></li>
195
<li><a href="ignore.html">Ignore</a></li>
196
<li><a href="maxtime.html">Maxtime</a></li>
197
<li><a href="pairwise.html">Pairwise</a></li>
198
<li><a href="platform.html">Platform</a></li>
199
<li><a href="property.html">Property</a></li>
200
<li><a href="random.html">Random</a></li>
201
<li><a href="range.html">Range</a></li>
202
<li><a href="repeat.html">Repeat</a></li>
203
<li><a href="requiredAddin.html">RequiredAddin</a></li>
204
<li><a href="requiresMTA.html">Requires MTA</a></li>
205
<li><a href="requiresSTA.html">Requires STA</a></li>
206
<li><a href="requiresThread.html">Requires Thread</a></li>
207
<li><a href="sequential.html">Sequential</a></li>
208
<li><a href="setCulture.html">SetCulture</a></li>
209
<li><a href="setUICulture.html">SetUICulture</a></li>
210
<li id="current"><a href="setup.html">Setup</a></li>
211
<li><a href="setupFixture.html">SetupFixture</a></li>
212
<li><a href="suite.html">Suite</a></li>
213
<li><a href="teardown.html">Teardown</a></li>
214
<li><a href="test.html">Test</a></li>
215
<li><a href="testCase.html">TestCase</a></li>
216
<li><a href="testCaseSource.html">TestCaseSource</a></li>
217
<li><a href="testFixture.html">TestFixture</a></li>
218
<li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
219
<li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
220
<li><a href="theory.html">Theory</a></li>
221
<li><a href="timeout.html">Timeout</a></li>
222
<li><a href="values.html">Values</a></li>
223
<li><a href="valueSource.html">ValueSource</a></li>
225
<li><a href="constraintModel.html">Constraints</a></li>
226
<li><a href="testContext.html">Test Context</a></li>
228
<li><a href="runningTests.html">Running Tests</a></li>
229
<li><a href="extensibility.html">Extensibility</a></li>
230
<li><a href="releaseNotes.html">Release Notes</a></li>
231
<li><a href="samples.html">Samples</a></li>
232
<li><a href="license.html">License</a></li>
234
<li><a href="vsTestAdapter.html">NUnit Test Adapter 0.90</a></li>
236
<li><a href="vsTestAdapterLicense.html">License</a></li>
238
<li><a href="&r=2.6.html"></a></li>
239
<li><a href="&r=2.6.html"></a></li>
242
<!-- End of Submenu -->
245
<!-- Standard Footer for NUnit.org -->
247
Copyright © 2012 Charlie Poole. All Rights Reserved.
249
<!-- End of Footer -->
24
<!-- End of Header -->
28
<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->
30
<h3>SetUpAttribute (NUnit 2.0 / 2.5)</h3>
32
<p>This attribute is used inside a <a href="testFixture.html">TestFixture</a> to provide a common set of functions that are performed just before each test method is called.
33
It is also used inside a <a href="setupFixture.html">SetUpFixture</a></b>,
34
where it provides the same functionality at the level of a namespace or assembly.
36
<p><b>Before NUnit 2.5</b>, a class could have only one SetUp method
37
and it was required to be an instance method.
39
<p><b>Beginning with NUnit 2.5</b>, SetUp methods may be either static or
40
instance methods and you may define more than one of them in a fixture.
41
Normally, multiple SetUp methods are only defined at different levels
42
of an inheritance hierarchy, as explained below.
44
<p>If a SetUp method fails or throws an exception, the test is not executed
45
and a failure or error is reported.
52
<div class="langFilter">
53
<a href="javascript:Show('DD1')" onmouseover="Show('DD1')"><img src="img/langFilter.gif" width="14" height="14" alt="Language Filter"></a>
54
<div id="DD1" class="dropdown" style="display: none" onclick="Hide('DD1')">
55
<a href="javascript:ShowCS()">C#</a><br>
56
<a href="javascript:ShowVB()">VB</a><br>
57
<a href="javascript:ShowMC()">C++</a><br>
58
<a href="javascript:ShowJS()">J#</a><br>
62
<pre class="cs">namespace NUnit.Tests
65
using NUnit.Framework;
68
public class SuccessTests
70
[SetUp] public void Init()
73
[TearDown] public void Cleanup()
76
[Test] public void Add()
82
<pre class="vb">Imports System
83
Imports Nunit.Framework
87
<TestFixture()> Public Class SuccessTests
88
<SetUp()> Public Sub Init()
92
<TearDown()> Public Sub Cleanup()
96
<Test()> Public Sub Add()
103
<pre class="mc">#using <Nunit.Framework.dll>
104
using namespace System;
105
using namespace NUnit::Framework;
110
public __gc class SuccessTests
113
[TearDown] void Cleanup();
119
#include "cppsample.h"
121
namespace NUnitTests {
126
<pre class="js">package NUnit.Tests;
129
import NUnit.Framework.TestFixture;
132
/** @attribute NUnit.Framework.TestFixture() */
133
public class SuccessTests
135
/** @attribute NUnit.Framework.SetUp() */
139
/** @attribute NUnit.Framework.TearDown() */
140
public void Cleanup()
143
/** @attribute NUnit.Framework.Test() */
153
<p>The SetUp attribute is inherited from any base class. Therefore, if a base
154
class has defined a SetUp method, that method will be called
155
before each test method in the derived class.
157
<p>Before NUnit 2.5, you were permitted only one SetUp method. If you wanted to
158
have some SetUp functionality in the base class and add more in the derived
159
class you needed to call the base class method yourself.
161
<p>With NUnit 2.5, you can achieve the same result by defining a SetUp method
162
in the base class and another in the derived class. NUnit will call base
163
class SetUp methods before those in the derived classes.
165
<p><b>Note:</b> Although it is possible to define multiple SetUp methods
166
in the same class, you should rarely do so. Unlike methods defined in
167
separate classes in the inheritance hierarchy, the order in which they
168
are executed is not guaranteed.
172
<li><a href="teardown.html">TearDownAttribute</a><li><a href="fixtureSetup.html">TestFixtureSetUpAttribute</a><li><a href="fixtureTeardown.html">TestFixtureTearDownAttribute</a><li><a href="setupFixture.html">SetUpFixtureAttribute</a></ul>
180
<li><a href="index.html">NUnit 2.6.3</a></li>
182
<li><a href="getStarted.html">Getting Started</a></li>
183
<li><a href="writingTests.html">Writing Tests</a></li>
185
<li><a href="assertions.html">Assertions</a></li>
186
<li><a href="attributes.html">Attributes</a></li>
188
<li><a href="actionAttributes.html">Action Attributes</a></li>
189
<li><a href="category.html">Category</a></li>
190
<li><a href="combinatorial.html">Combinatorial</a></li>
191
<li><a href="culture.html">Culture</a></li>
192
<li><a href="datapoint.html">Datapoint(s)</a></li>
193
<li><a href="description.html">Description</a></li>
194
<li><a href="exception.html">Exception</a></li>
195
<li><a href="explicit.html">Explicit</a></li>
196
<li><a href="ignore.html">Ignore</a></li>
197
<li><a href="maxtime.html">Maxtime</a></li>
198
<li><a href="pairwise.html">Pairwise</a></li>
199
<li><a href="platform.html">Platform</a></li>
200
<li><a href="property.html">Property</a></li>
201
<li><a href="random.html">Random</a></li>
202
<li><a href="range.html">Range</a></li>
203
<li><a href="repeat.html">Repeat</a></li>
204
<li><a href="requiredAddin.html">RequiredAddin</a></li>
205
<li><a href="requiresMTA.html">Requires MTA</a></li>
206
<li><a href="requiresSTA.html">Requires STA</a></li>
207
<li><a href="requiresThread.html">Requires Thread</a></li>
208
<li><a href="sequential.html">Sequential</a></li>
209
<li><a href="setCulture.html">SetCulture</a></li>
210
<li><a href="setUICulture.html">SetUICulture</a></li>
211
<li id="current"><a href="setup.html">Setup</a></li>
212
<li><a href="setupFixture.html">SetupFixture</a></li>
213
<li><a href="suite.html">Suite</a></li>
214
<li><a href="teardown.html">Teardown</a></li>
215
<li><a href="test.html">Test</a></li>
216
<li><a href="testCase.html">TestCase</a></li>
217
<li><a href="testCaseSource.html">TestCaseSource</a></li>
218
<li><a href="testFixture.html">TestFixture</a></li>
219
<li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
220
<li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
221
<li><a href="theory.html">Theory</a></li>
222
<li><a href="timeout.html">Timeout</a></li>
223
<li><a href="values.html">Values</a></li>
224
<li><a href="valueSource.html">ValueSource</a></li>
226
<li><a href="testContext.html">Test Context</a></li>
228
<li><a href="runningTests.html">Running Tests</a></li>
229
<li><a href="extensibility.html">Extensibility</a></li>
230
<li><a href="releaseNotes.html">Release Notes</a></li>
231
<li><a href="samples.html">Samples</a></li>
232
<li><a href="license.html">License</a></li>
234
<li><a href="vsTestAdapter.html">NUnit Test Adapter</a></li>
236
<li><a href="vsTestAdapterLicense.html">License</a></li>
237
<li><a href="vsTestAdapterReleaseNotes.html">Release Notes</a></li>
239
<li><a href="&r=2.6.3.html"></a></li>
240
<li><a href="&r=2.6.3.html"></a></li>
243
<!-- End of Submenu -->
246
<!-- Standard Footer for NUnit.org -->
248
Copyright © 2012 Charlie Poole. All Rights Reserved.
250
<!-- End of Footer -->