[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 - Assertions</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 | <h2>Assertions</h2>
|
---|
| 28 |
|
---|
| 29 | <p>Assertions are central to unit testing in any of the xUnit frameworks, and NUnit
|
---|
| 30 | is no exception. NUnit provides a rich set of assertions as static methods of
|
---|
| 31 | the Assert class.</p>
|
---|
| 32 |
|
---|
| 33 | <p>If an assertion fails, the method call does not return and an error is reported.
|
---|
| 34 | If a test contains multiple assertions, any that follow the one that failed
|
---|
| 35 | will not be executed. For this reason, it's usually best to try for one
|
---|
| 36 | assertion per test.</p>
|
---|
| 37 |
|
---|
| 38 | <p>Each method may be called without a message, with a simple text message or with
|
---|
| 39 | a message and arguments. In the last case the message is formatted using the
|
---|
| 40 | provided text and arguments.</p>
|
---|
| 41 |
|
---|
| 42 | <h3>Two Models</h3>
|
---|
| 43 |
|
---|
| 44 | <p>Before NUnit 2.4, a separate method of the Assert class was used for each
|
---|
| 45 | different assertion. We call this the "Classic Model." It
|
---|
| 46 | continues to be supported in NUnit, since many people prefer it.</p>
|
---|
| 47 |
|
---|
| 48 | <p>Beginning with NUnit 2.4, a new "Constraint-based" model was
|
---|
| 49 | introduced. This approach uses a single method of the Assert class
|
---|
| 50 | for all assertions, passing a <a href="constraintModel.html">Constraint</a> object that specifies the test to be performed.
|
---|
| 51 |
|
---|
| 52 | <p>This constraint-based model is now used internally by NUnit
|
---|
| 53 | for all assertions. The methods of the classic approach have been
|
---|
| 54 | re-implemented on top of this new model.
|
---|
| 55 |
|
---|
| 56 | <!--
|
---|
| 57 | <h4>See Also...</h4>
|
---|
| 58 | <ul>
|
---|
| 59 | <li>
|
---|
| 60 | </ul>
|
---|
| 61 | -->
|
---|
| 62 |
|
---|
| 63 | </div>
|
---|
| 64 |
|
---|
| 65 | <!-- Submenu -->
|
---|
| 66 | <div id="subnav">
|
---|
| 67 | <ul>
|
---|
| 68 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
| 69 | <ul>
|
---|
| 70 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
| 71 | <li id="current"><a href="assertions.html">Assertions</a></li>
|
---|
| 72 | <ul>
|
---|
| 73 | <li><a href="equalityAsserts.html">Equality Asserts</a></li>
|
---|
| 74 | <li><a href="identityAsserts.html">Identity Asserts</a></li>
|
---|
| 75 | <li><a href="conditionAsserts.html">Condition Asserts</a></li>
|
---|
| 76 | <li><a href="comparisonAsserts.html">Comparison Asserts</a></li>
|
---|
| 77 | <li><a href="typeAsserts.html">Type Asserts</a></li>
|
---|
| 78 | <li><a href="exceptionAsserts.html">Exception Asserts</a></li>
|
---|
| 79 | <li><a href="utilityAsserts.html">Utility Methods</a></li>
|
---|
| 80 | <li><a href="stringAssert.html">String Assert</a></li>
|
---|
| 81 | <li><a href="collectionAssert.html">Collection Assert</a></li>
|
---|
| 82 | <li><a href="fileAssert.html">File Assert</a></li>
|
---|
| 83 | <li><a href="directoryAssert.html">Directory Assert</a></li>
|
---|
| 84 | </ul>
|
---|
| 85 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
| 86 | <li><a href="attributes.html">Attributes</a></li>
|
---|
| 87 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
| 88 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
| 89 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
| 90 | <li><a href="samples.html">Samples</a></li>
|
---|
| 91 | <li><a href="license.html">License</a></li>
|
---|
| 92 | </ul>
|
---|
| 93 | </ul>
|
---|
| 94 | </div>
|
---|
| 95 | <!-- End of Submenu -->
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | <!-- Standard Footer for NUnit.org -->
|
---|
| 99 | <div id="footer">
|
---|
| 100 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
| 101 | </div>
|
---|
| 102 | <!-- End of Footer -->
|
---|
| 103 |
|
---|
| 104 | </body>
|
---|
| 105 | </html>
|
---|