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 - ValueSource</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>ValueSourceAttribute (NUnit 2.5)</h3>
|
---|
30 |
|
---|
31 | <p><b>ValueSourceAttribute</b> is used on individual parameters of a test method to
|
---|
32 | identify a named source for the argument values to be supplied. The attribute has
|
---|
33 | two public constructors.
|
---|
34 |
|
---|
35 | <div class="code">
|
---|
36 | <pre>
|
---|
37 | ValueSourceAttribute(Type sourceType, string sourceName);
|
---|
38 | ValueSourceAttribute(string sourceName);
|
---|
39 | </pre>
|
---|
40 | </div>
|
---|
41 |
|
---|
42 | <p>If <b>sourceType</b> is specified, it represents the class that provides
|
---|
43 | the data. It must have a default constructor.
|
---|
44 |
|
---|
45 | <p>If <b>sourceType</b> is not specified, the class containing the test
|
---|
46 | method is used. NUnit will construct it using either the default constructor
|
---|
47 | or - if arguments are provided - the appropriate constructor for those
|
---|
48 | arguments.
|
---|
49 |
|
---|
50 | <p>The <b>sourceName</b>, represents the name of the source that will
|
---|
51 | provide the arguments. It should have the following characteristics:
|
---|
52 | <ul>
|
---|
53 | <li>It may be a field, a non-indexed property or a method taking no arguments.
|
---|
54 | <li>It may be either an instance or a static member.
|
---|
55 | <li>It must return an IEnumerable or a type that implements IEnumerable.
|
---|
56 | <li>The individual items returned from the enumerator must be compatible
|
---|
57 | with the type of the parameter on which the attribute appears.
|
---|
58 | </ul>
|
---|
59 |
|
---|
60 | <h3>Order of Execution</h3>
|
---|
61 |
|
---|
62 | <p>In NUnit 2.5, individual test cases are sorted alphabetically and executed in
|
---|
63 | that order. With NUnit 2.5.1, the individual cases are not sorted, but are
|
---|
64 | executed in the order in which NUnit discovers them. This order does <b>not</b>
|
---|
65 | follow the lexical order of the attributes and will often vary between different
|
---|
66 | compilers or different versions of the CLR.
|
---|
67 |
|
---|
68 | <p>As a result, when <b>ValueSourceAttribute</b> appears multiple times on a
|
---|
69 | parameter or when other data-providing attributes are used in combination with
|
---|
70 | <b>ValueSourceAttribute</b>, the order of the arguments is undefined.
|
---|
71 |
|
---|
72 | <p>However, when a single <b>ValueSourceAttribute</b> is used by itself,
|
---|
73 | the order of the arguments follows exactly the order in which the data
|
---|
74 | is returned from the source.
|
---|
75 |
|
---|
76 | <h3>Note on Object Construction</h3>
|
---|
77 |
|
---|
78 | <p>NUnit locates the test cases at the time the tests are loaded, creates
|
---|
79 | instances of each class with non-static sources and builds a list of
|
---|
80 | tests to be executed. Each source object is only created once at this
|
---|
81 | time and is destroyed after all tests are loaded.
|
---|
82 |
|
---|
83 | <p>If the data source is in the test fixture itself, the object is created
|
---|
84 | using the appropriate constructor for the fixture parameters provided on
|
---|
85 | the <b>TestFixtureAttribute</b>, or
|
---|
86 | the default constructor if no parameters were specified. Since this object
|
---|
87 | is destroyed before the tests are run, no communication is possible between
|
---|
88 | these two phases - or between different runs - except through the parameters
|
---|
89 | themselves.
|
---|
90 |
|
---|
91 | </div>
|
---|
92 |
|
---|
93 | <!-- Submenu -->
|
---|
94 | <div id="subnav">
|
---|
95 | <ul>
|
---|
96 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
97 | <ul>
|
---|
98 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
99 | <li><a href="assertions.html">Assertions</a></li>
|
---|
100 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
101 | <li><a href="attributes.html">Attributes</a></li>
|
---|
102 | <ul>
|
---|
103 | <li><a href="category.html">Category</a></li>
|
---|
104 | <li><a href="combinatorial.html">Combinatorial</a></li>
|
---|
105 | <li><a href="culture.html">Culture</a></li>
|
---|
106 | <li><a href="datapoint.html">Datapoint(s)</a></li>
|
---|
107 | <li><a href="description.html">Description</a></li>
|
---|
108 | <li><a href="exception.html">Exception</a></li>
|
---|
109 | <li><a href="explicit.html">Explicit</a></li>
|
---|
110 | <li><a href="ignore.html">Ignore</a></li>
|
---|
111 | <li><a href="maxtime.html">Maxtime</a></li>
|
---|
112 | <li><a href="pairwise.html">Pairwise</a></li>
|
---|
113 | <li><a href="platform.html">Platform</a></li>
|
---|
114 | <li><a href="property.html">Property</a></li>
|
---|
115 | <li><a href="random.html">Random</a></li>
|
---|
116 | <li><a href="range.html">Range</a></li>
|
---|
117 | <li><a href="repeat.html">Repeat</a></li>
|
---|
118 | <li><a href="requiredAddin.html">RequiredAddin</a></li>
|
---|
119 | <li><a href="requiresMTA.html">Requires MTA</a></li>
|
---|
120 | <li><a href="requiresSTA.html">Requires STA</a></li>
|
---|
121 | <li><a href="requiresThread.html">Requires Thread</a></li>
|
---|
122 | <li><a href="sequential.html">Sequential</a></li>
|
---|
123 | <li><a href="setCulture.html">SetCulture</a></li>
|
---|
124 | <li><a href="setUICulture.html">SetUICulture</a></li>
|
---|
125 | <li><a href="setup.html">Setup</a></li>
|
---|
126 | <li><a href="setupFixture.html">SetupFixture</a></li>
|
---|
127 | <li><a href="suite.html">Suite</a></li>
|
---|
128 | <li><a href="teardown.html">Teardown</a></li>
|
---|
129 | <li><a href="test.html">Test</a></li>
|
---|
130 | <li><a href="testCase.html">TestCase</a></li>
|
---|
131 | <li><a href="testCaseSource.html">TestCaseSource</a></li>
|
---|
132 | <li><a href="testFixture.html">TestFixture</a></li>
|
---|
133 | <li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
|
---|
134 | <li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
|
---|
135 | <li><a href="theory.html">Theory</a></li>
|
---|
136 | <li><a href="timeout.html">Timeout</a></li>
|
---|
137 | <li><a href="values.html">Values</a></li>
|
---|
138 | <li id="current"><a href="valueSource.html">ValueSource</a></li>
|
---|
139 | </ul>
|
---|
140 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
141 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
142 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
143 | <li><a href="samples.html">Samples</a></li>
|
---|
144 | <li><a href="license.html">License</a></li>
|
---|
145 | </ul>
|
---|
146 | </ul>
|
---|
147 | </div>
|
---|
148 | <!-- End of Submenu -->
|
---|
149 |
|
---|
150 |
|
---|
151 | <!-- Standard Footer for NUnit.org -->
|
---|
152 | <div id="footer">
|
---|
153 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
154 | </div>
|
---|
155 | <!-- End of Footer -->
|
---|
156 |
|
---|
157 | </body>
|
---|
158 | </html>
|
---|