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

« back to all changes in this revision

Viewing changes to doc/setup.html

  • 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
 
<!-- 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 - 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">
11
 
</head>
12
 
<!-- End Standard Head Part -->
13
 
 
14
 
<body>
15
 
 
16
 
<!-- Standard Header for NUnit.org -->
17
 
<div id="header">
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">
 
2
<html>
 
3
<!-- Standard Head Part -->
 
4
<head>
 
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">
 
11
</head>
 
12
<!-- End Standard Head Part -->
 
13
 
 
14
<body>
 
15
 
 
16
<!-- Standard Header for NUnit.org -->
 
17
<div id="header">
 
18
  <a id="logo" href="http://www.nunit.org"><img src="img/logo.gif" alt="NUnit.org" title="NUnit.org"></a>
19
19
  <div id="nav">
20
20
    <a href="http://www.nunit.org">NUnit</a>
21
21
    <a class="active" href="index.html">Documentation</a>
22
 
  </div>
23
 
</div>
24
 
<!-- End of Header -->
25
 
 
26
 
<div id="content">
27
 
 
28
 
<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->
29
 
 
30
 
<h3>SetUpAttribute (NUnit 2.0 / 2.5)</h3>
31
 
 
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.  
34
 
    
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. 
37
 
 
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.
42
 
   
43
 
<p>If a SetUp method fails or throws an exception, the test is not executed
44
 
   and a failure or error is reported.
45
 
   
46
 
 
47
 
<h4>Example:</h4>
48
 
 
49
 
<div class="code">
50
 
 
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>
58
 
        </div>
59
 
</div>
60
 
 
61
 
<pre class="cs">namespace NUnit.Tests
62
 
{
63
 
  using System;
64
 
  using NUnit.Framework;
65
 
 
66
 
  [TestFixture]
67
 
  public class SuccessTests
68
 
  {
69
 
    [SetUp] public void Init()
70
 
    { /* ... */ }
71
 
 
72
 
    [TearDown] public void Cleanup()
73
 
    { /* ... */ }
74
 
 
75
 
    [Test] public void Add()
76
 
    { /* ... */ }
77
 
  }
78
 
}
79
 
</pre>
80
 
 
81
 
<pre class="vb">Imports System
82
 
Imports Nunit.Framework
83
 
 
84
 
Namespace Nunit.Tests
85
 
 
86
 
  &lt;TestFixture()&gt; Public Class SuccessTests
87
 
    &lt;SetUp()&gt; Public Sub Init()
88
 
    ' ...
89
 
    End Sub
90
 
 
91
 
    &lt;TearDown()&gt; Public Sub Cleanup()
92
 
    ' ...
93
 
    End Sub
94
 
 
95
 
    &lt;Test()&gt; Public Sub Add()
96
 
    ' ...
97
 
    End Sub
98
 
  End Class
99
 
End Namespace
100
 
</pre>
101
 
 
102
 
<pre class="mc">#using &lt;Nunit.Framework.dll&gt;
103
 
using namespace System;
104
 
using namespace NUnit::Framework;
105
 
 
106
 
namespace NUnitTests
107
 
{
108
 
  [TestFixture]
109
 
  public __gc class SuccessTests
110
 
  {
111
 
    [SetUp] void Init();
112
 
    [TearDown] void Cleanup();
113
 
 
114
 
    [Test] void Add();
115
 
  };
116
 
}
117
 
 
118
 
#include "cppsample.h"
119
 
 
120
 
namespace NUnitTests {
121
 
  // ...
122
 
}
123
 
</pre>
124
 
 
125
 
<pre class="js">package NUnit.Tests;
126
 
 
127
 
import System.*;
128
 
import NUnit.Framework.TestFixture;
129
 
 
130
 
 
131
 
/** @attribute NUnit.Framework.TestFixture() */
132
 
public class SuccessTests
133
 
{
134
 
  /** @attribute NUnit.Framework.SetUp() */
135
 
  public void Init()
136
 
  { /* ... */ }
137
 
 
138
 
  /** @attribute NUnit.Framework.TearDown() */
139
 
  public void Cleanup()
140
 
  { /* ... */ }
141
 
 
142
 
  /** @attribute NUnit.Framework.Test() */
143
 
  public void Add()
144
 
  { /* ... */ }
145
 
}
146
 
</pre>
147
 
 
148
 
</div>
149
 
 
150
 
<h3>Inheritance</h3>
151
 
 
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.
155
 
        
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.
159
 
 
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.
163
 
   
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.
168
 
 
169
 
<h4>See also...</h4>
170
 
<ul>
171
 
<li><a href="teardown.html">TearDownAttribute</a><li><a href="fixtureSetup.html">TestFixtureSetUpAttribute</a><li><a href="fixtureTeardown.html">TestFixtureTearDownAttribute</a></ul>
172
 
        
173
 
 
174
 
</div>
175
 
 
176
 
<!-- Submenu -->
177
 
<div id="subnav">
178
 
<ul>
179
 
<li><a href="index.html">NUnit 2.6</a></li>
180
 
<ul>
181
 
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
182
 
<li><a href="writingTests.html">Writing&nbsp;Tests</a></li>
183
 
<ul>
184
 
<li><a href="assertions.html">Assertions</a></li>
185
 
<li><a href="attributes.html">Attributes</a></li>
186
 
<ul>
187
 
<li><a href="actionAttributes.html">Action&nbsp;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&nbsp;MTA</a></li>
205
 
<li><a href="requiresSTA.html">Requires&nbsp;STA</a></li>
206
 
<li><a href="requiresThread.html">Requires&nbsp;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>
224
 
</ul>
225
 
<li><a href="constraintModel.html">Constraints</a></li>
226
 
<li><a href="testContext.html">Test&nbsp;Context</a></li>
227
 
</ul>
228
 
<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
229
 
<li><a href="extensibility.html">Extensibility</a></li>
230
 
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
231
 
<li><a href="samples.html">Samples</a></li>
232
 
<li><a href="license.html">License</a></li>
233
 
</ul>
234
 
<li><a href="vsTestAdapter.html">NUnit&nbsp;Test&nbsp;Adapter&nbsp;0.90</a></li>
235
 
<ul>
236
 
<li><a href="vsTestAdapterLicense.html">License</a></li>
237
 
</ul>
238
 
<li><a href="&r=2.6.html"></a></li>
239
 
<li><a href="&r=2.6.html"></a></li>
240
 
</ul>
241
 
</div>
242
 
<!-- End of Submenu -->
243
 
 
244
 
 
245
 
<!-- Standard Footer for NUnit.org -->
246
 
<div id="footer">
247
 
  Copyright &copy; 2012 Charlie Poole. All Rights Reserved.
248
 
</div>
249
 
<!-- End of Footer -->
250
 
 
251
 
</body>
252
 
</html>
 
22
  </div>
 
23
</div>
 
24
<!-- End of Header -->
 
25
 
 
26
<div id="content">
 
27
 
 
28
<script language="JavaScript" src="codeFuncs.js" ></script> <!-- Do it this way for IE -->
 
29
 
 
30
<h3>SetUpAttribute (NUnit 2.0 / 2.5)</h3>
 
31
 
 
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.
 
35
    
 
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. 
 
38
 
 
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.
 
43
   
 
44
<p>If a SetUp method fails or throws an exception, the test is not executed
 
45
   and a failure or error is reported.
 
46
   
 
47
 
 
48
<h4>Example:</h4>
 
49
 
 
50
<div class="code">
 
51
 
 
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>
 
59
        </div>
 
60
</div>
 
61
 
 
62
<pre class="cs">namespace NUnit.Tests
 
63
{
 
64
  using System;
 
65
  using NUnit.Framework;
 
66
 
 
67
  [TestFixture]
 
68
  public class SuccessTests
 
69
  {
 
70
    [SetUp] public void Init()
 
71
    { /* ... */ }
 
72
 
 
73
    [TearDown] public void Cleanup()
 
74
    { /* ... */ }
 
75
 
 
76
    [Test] public void Add()
 
77
    { /* ... */ }
 
78
  }
 
79
}
 
80
</pre>
 
81
 
 
82
<pre class="vb">Imports System
 
83
Imports Nunit.Framework
 
84
 
 
85
Namespace Nunit.Tests
 
86
 
 
87
  &lt;TestFixture()&gt; Public Class SuccessTests
 
88
    &lt;SetUp()&gt; Public Sub Init()
 
89
    ' ...
 
90
    End Sub
 
91
 
 
92
    &lt;TearDown()&gt; Public Sub Cleanup()
 
93
    ' ...
 
94
    End Sub
 
95
 
 
96
    &lt;Test()&gt; Public Sub Add()
 
97
    ' ...
 
98
    End Sub
 
99
  End Class
 
100
End Namespace
 
101
</pre>
 
102
 
 
103
<pre class="mc">#using &lt;Nunit.Framework.dll&gt;
 
104
using namespace System;
 
105
using namespace NUnit::Framework;
 
106
 
 
107
namespace NUnitTests
 
108
{
 
109
  [TestFixture]
 
110
  public __gc class SuccessTests
 
111
  {
 
112
    [SetUp] void Init();
 
113
    [TearDown] void Cleanup();
 
114
 
 
115
    [Test] void Add();
 
116
  };
 
117
}
 
118
 
 
119
#include "cppsample.h"
 
120
 
 
121
namespace NUnitTests {
 
122
  // ...
 
123
}
 
124
</pre>
 
125
 
 
126
<pre class="js">package NUnit.Tests;
 
127
 
 
128
import System.*;
 
129
import NUnit.Framework.TestFixture;
 
130
 
 
131
 
 
132
/** @attribute NUnit.Framework.TestFixture() */
 
133
public class SuccessTests
 
134
{
 
135
  /** @attribute NUnit.Framework.SetUp() */
 
136
  public void Init()
 
137
  { /* ... */ }
 
138
 
 
139
  /** @attribute NUnit.Framework.TearDown() */
 
140
  public void Cleanup()
 
141
  { /* ... */ }
 
142
 
 
143
  /** @attribute NUnit.Framework.Test() */
 
144
  public void Add()
 
145
  { /* ... */ }
 
146
}
 
147
</pre>
 
148
 
 
149
</div>
 
150
 
 
151
<h3>Inheritance</h3>
 
152
 
 
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.
 
156
        
 
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.
 
160
 
 
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.
 
164
   
 
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.
 
169
 
 
170
<h4>See also...</h4>
 
171
<ul>
 
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>
 
173
        
 
174
 
 
175
</div>
 
176
 
 
177
<!-- Submenu -->
 
178
<div id="subnav">
 
179
<ul>
 
180
<li><a href="index.html">NUnit 2.6.3</a></li>
 
181
<ul>
 
182
<li><a href="getStarted.html">Getting&nbsp;Started</a></li>
 
183
<li><a href="writingTests.html">Writing&nbsp;Tests</a></li>
 
184
<ul>
 
185
<li><a href="assertions.html">Assertions</a></li>
 
186
<li><a href="attributes.html">Attributes</a></li>
 
187
<ul>
 
188
<li><a href="actionAttributes.html">Action&nbsp;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&nbsp;MTA</a></li>
 
206
<li><a href="requiresSTA.html">Requires&nbsp;STA</a></li>
 
207
<li><a href="requiresThread.html">Requires&nbsp;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>
 
225
</ul>
 
226
<li><a href="testContext.html">Test&nbsp;Context</a></li>
 
227
</ul>
 
228
<li><a href="runningTests.html">Running&nbsp;Tests</a></li>
 
229
<li><a href="extensibility.html">Extensibility</a></li>
 
230
<li><a href="releaseNotes.html">Release&nbsp;Notes</a></li>
 
231
<li><a href="samples.html">Samples</a></li>
 
232
<li><a href="license.html">License</a></li>
 
233
</ul>
 
234
<li><a href="vsTestAdapter.html">NUnit&nbsp;Test&nbsp;Adapter</a></li>
 
235
<ul>
 
236
<li><a href="vsTestAdapterLicense.html">License</a></li>
 
237
<li><a href="vsTestAdapterReleaseNotes.html">Release&nbsp;Notes</a></li>
 
238
</ul>
 
239
<li><a href="&r=2.6.3.html"></a></li>
 
240
<li><a href="&r=2.6.3.html"></a></li>
 
241
</ul>
 
242
</div>
 
243
<!-- End of Submenu -->
 
244
 
 
245
 
 
246
<!-- Standard Footer for NUnit.org -->
 
247
<div id="footer">
 
248
  Copyright &copy; 2012 Charlie Poole. All Rights Reserved.
 
249
</div>
 
250
<!-- End of Footer -->
 
251
 
 
252
</body>
 
253
</html>