[1146] | 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 - TestCase</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>TestCaseAttribute (NUnit 2.5)</h3>
|
---|
| 30 |
|
---|
| 31 | <p><b>TestCaseAttribute</b> serves the dual purpose of marking a method with
|
---|
| 32 | parameters as a test method and providing inline data to be used when
|
---|
| 33 | invoking that method. Here is an example of a test being run three
|
---|
| 34 | times, with three different sets of data:
|
---|
| 35 |
|
---|
| 36 | <div class="code">
|
---|
| 37 | <pre>[TestCase(12,3,4)]
|
---|
| 38 | [TestCase(12,2,6)]
|
---|
| 39 | [TestCase(12,4,3)]
|
---|
| 40 | public void DivideTest(int n, int d, int q)
|
---|
| 41 | {
|
---|
| 42 | Assert.AreEqual( q, n / d );
|
---|
| 43 | }
|
---|
| 44 | </pre>
|
---|
| 45 | </div>
|
---|
| 46 |
|
---|
| 47 | <p><b>Note:</b> Because arguments to .NET attributes are limited in terms of the
|
---|
| 48 | Types that may be used, NUnit will make some attempt to convert the supplied
|
---|
| 49 | values using <b>Convert.ChangeType()</b> before supplying it to the test.
|
---|
| 50 |
|
---|
| 51 | <p><b>TestCaseAttribute</b> may appear one or more times on a test method,
|
---|
| 52 | which may also carry other attributes providing test data, such as the
|
---|
| 53 | <a href="factories.html">FactoriesAttribute</a>.
|
---|
| 54 | The method may optionally be marked with the
|
---|
| 55 | <a href="test.html">TestAttribute</a> as well.
|
---|
| 56 |
|
---|
| 57 | <p>By using the named parameter <b>Result</b> this test set may be simplified
|
---|
| 58 | further:
|
---|
| 59 |
|
---|
| 60 | <div class="code">
|
---|
| 61 | <pre>[TestCase(12,3, Result=4)]
|
---|
| 62 | [TestCase(12,2, Result=6)]
|
---|
| 63 | [TestCase(12,4, Result=3)]
|
---|
| 64 | public int DivideTest(int n, int d)
|
---|
| 65 | {
|
---|
| 66 | return( n / d );
|
---|
| 67 | }
|
---|
| 68 | </pre>
|
---|
| 69 | </div>
|
---|
| 70 |
|
---|
| 71 | <p>In the above example, NUnit checks that the return
|
---|
| 72 | value of the method is equal to the expected result provided on the attribut
|
---|
| 73 |
|
---|
| 74 | <p><b>TestCaseAttribute</b> supports a number of additional
|
---|
| 75 | named parameters, which may be used as follows:
|
---|
| 76 |
|
---|
| 77 | <dl>
|
---|
| 78 | <dt><b>Description</b>
|
---|
| 79 | <dd>Sets the description property of the test
|
---|
| 80 | <dt><b>ExpectedException</b>
|
---|
| 81 | <dd>Specifies a the Type of an exception that should be thrown by this invocation
|
---|
| 82 | <dt><b>ExpectedExceptionName</b>
|
---|
| 83 | <dd>Specifies a the FullName of an exception that should be thrown by this invocation
|
---|
| 84 | <dt><b>ExpectedMessage</b>
|
---|
| 85 | <dd>Specifies the message text of the expected exception
|
---|
| 86 | <dt><b>MatchType</b>
|
---|
| 87 | <dd>A <b>MessageMatch</b> enum value indicating how to test the expected message
|
---|
| 88 | (See <a href="exception.html">ExpectedExceptionAttribute</a>)
|
---|
| 89 | <dt><b>Result</b>
|
---|
| 90 | <dd>The expected result to be returned from the method, which must have
|
---|
| 91 | a compatible return type.
|
---|
| 92 | <dt><b>TestName</b>
|
---|
| 93 | <dd>Provides a name for the test. If not specified, a name is generated based on
|
---|
| 94 | the method name and the arguments provided.
|
---|
| 95 | <dt><b>Ignore</b>
|
---|
| 96 | <dd>Set to true in order to ignore the individual test case.
|
---|
| 97 | <dt><b>IgnoreReason</b>
|
---|
| 98 | <dd>Specifies the reason for ignoring this test case. If set to a non-empty
|
---|
| 99 | string, then Ignore is assumed to be true.
|
---|
| 100 | </dl>
|
---|
| 101 |
|
---|
| 102 | <h3>Order of Execution</h3>
|
---|
| 103 |
|
---|
| 104 | <p>In NUnit 2.5, individual test cases are sorted alphabetically and executed in
|
---|
| 105 | that order. With NUnit 2.5.1, the individual cases are not sorted, but are
|
---|
| 106 | executed in the order in which NUnit discovers them. This order does <b>not</b>
|
---|
| 107 | follow the lexical order of the attributes and will often vary between different
|
---|
| 108 | compilers or different versions of the CLR.
|
---|
| 109 |
|
---|
| 110 | <p>As a result, when <b>TestCaseAttribute</b> appears multiple times on a method
|
---|
| 111 | or when other data-providing attributes are used in combination with
|
---|
| 112 | <b>TestCaseAttribute</b>, the order of the test cases is undefined.
|
---|
| 113 |
|
---|
| 114 | </div>
|
---|
| 115 |
|
---|
| 116 | <!-- Submenu -->
|
---|
| 117 | <div id="subnav">
|
---|
| 118 | <ul>
|
---|
| 119 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
| 120 | <ul>
|
---|
| 121 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
| 122 | <li><a href="assertions.html">Assertions</a></li>
|
---|
| 123 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
| 124 | <li><a href="attributes.html">Attributes</a></li>
|
---|
| 125 | <ul>
|
---|
| 126 | <li><a href="category.html">Category</a></li>
|
---|
| 127 | <li><a href="combinatorial.html">Combinatorial</a></li>
|
---|
| 128 | <li><a href="culture.html">Culture</a></li>
|
---|
| 129 | <li><a href="datapoint.html">Datapoint(s)</a></li>
|
---|
| 130 | <li><a href="description.html">Description</a></li>
|
---|
| 131 | <li><a href="exception.html">Exception</a></li>
|
---|
| 132 | <li><a href="explicit.html">Explicit</a></li>
|
---|
| 133 | <li><a href="ignore.html">Ignore</a></li>
|
---|
| 134 | <li><a href="maxtime.html">Maxtime</a></li>
|
---|
| 135 | <li><a href="pairwise.html">Pairwise</a></li>
|
---|
| 136 | <li><a href="platform.html">Platform</a></li>
|
---|
| 137 | <li><a href="property.html">Property</a></li>
|
---|
| 138 | <li><a href="random.html">Random</a></li>
|
---|
| 139 | <li><a href="range.html">Range</a></li>
|
---|
| 140 | <li><a href="repeat.html">Repeat</a></li>
|
---|
| 141 | <li><a href="requiredAddin.html">RequiredAddin</a></li>
|
---|
| 142 | <li><a href="requiresMTA.html">Requires MTA</a></li>
|
---|
| 143 | <li><a href="requiresSTA.html">Requires STA</a></li>
|
---|
| 144 | <li><a href="requiresThread.html">Requires Thread</a></li>
|
---|
| 145 | <li><a href="sequential.html">Sequential</a></li>
|
---|
| 146 | <li><a href="setCulture.html">SetCulture</a></li>
|
---|
| 147 | <li><a href="setUICulture.html">SetUICulture</a></li>
|
---|
| 148 | <li><a href="setup.html">Setup</a></li>
|
---|
| 149 | <li><a href="setupFixture.html">SetupFixture</a></li>
|
---|
| 150 | <li><a href="suite.html">Suite</a></li>
|
---|
| 151 | <li><a href="teardown.html">Teardown</a></li>
|
---|
| 152 | <li><a href="test.html">Test</a></li>
|
---|
| 153 | <li id="current"><a href="testCase.html">TestCase</a></li>
|
---|
| 154 | <li><a href="testCaseSource.html">TestCaseSource</a></li>
|
---|
| 155 | <li><a href="testFixture.html">TestFixture</a></li>
|
---|
| 156 | <li><a href="fixtureSetup.html">TestFixtureSetUp</a></li>
|
---|
| 157 | <li><a href="fixtureTeardown.html">TestFixtureTearDown</a></li>
|
---|
| 158 | <li><a href="theory.html">Theory</a></li>
|
---|
| 159 | <li><a href="timeout.html">Timeout</a></li>
|
---|
| 160 | <li><a href="values.html">Values</a></li>
|
---|
| 161 | <li><a href="valueSource.html">ValueSource</a></li>
|
---|
| 162 | </ul>
|
---|
| 163 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
| 164 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
| 165 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
| 166 | <li><a href="samples.html">Samples</a></li>
|
---|
| 167 | <li><a href="license.html">License</a></li>
|
---|
| 168 | </ul>
|
---|
| 169 | </ul>
|
---|
| 170 | </div>
|
---|
| 171 | <!-- End of Submenu -->
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | <!-- Standard Footer for NUnit.org -->
|
---|
| 175 | <div id="footer">
|
---|
| 176 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
| 177 | </div>
|
---|
| 178 | <!-- End of Footer -->
|
---|
| 179 |
|
---|
| 180 | </body>
|
---|
| 181 | </html>
|
---|