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 - UtilityAsserts</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>Utility Methods</h2>
|
---|
28 | <p>Four utility methods, <b>Pass()</b>, <b>Fail()</b>, <b>Ignore()</b> and <b>Inconclusive()</b> are provided
|
---|
29 | in order to allow more direct control of the test process:</p>
|
---|
30 | <div class="code" style="width: 36em"><pre>
|
---|
31 | Assert.Pass();
|
---|
32 | Assert.Pass( string message );
|
---|
33 | Assert.Pass( string message, object[] parms );
|
---|
34 |
|
---|
35 | Assert.Fail();
|
---|
36 | Assert.Fail( string message );
|
---|
37 | Assert.Fail( string message, object[] parms );
|
---|
38 |
|
---|
39 | Assert.Ignore();
|
---|
40 | Assert.Ignore( string message );
|
---|
41 | Assert.Ignore( string message, object[] parms );
|
---|
42 |
|
---|
43 | Assert.Inconclusive();
|
---|
44 | Assert.Inconclusive( string message );
|
---|
45 | Assert.Inconclusive( string message, object[] parms );</pre>
|
---|
46 | </div>
|
---|
47 | <p>The <b>Assert.Pass</b> method allows you to immediately end the test, recording
|
---|
48 | it as successful. Since it causes an exception to be thrown, it is more
|
---|
49 | efficient to simply allow the test to return. However, Assert.Pass allows
|
---|
50 | you to record a message in the test result and may also make the test
|
---|
51 | easier to read in some situations. Additionally, like the other methods
|
---|
52 | on this page, it can be invoked from a nested method call with the
|
---|
53 | result of immediately terminating test execution.</p>
|
---|
54 | <p>The <b>Assert.Fail</b> method provides you with the ability to generate a failure based
|
---|
55 | on tests that are not encapsulated by the other methods. It is also useful in
|
---|
56 | developing your own project-specific assertions.</p>
|
---|
57 | <p>Here's an example of its use to create a private assertion that tests whether a
|
---|
58 | string contains an expected value.</p>
|
---|
59 | <div class="code" style="width: 36em">
|
---|
60 | <pre>public void AssertStringContains( string expected, string actual )
|
---|
61 | {
|
---|
62 | AssertStringContains( expected, actual, string.Empty );
|
---|
63 | }
|
---|
64 |
|
---|
65 | public void AssertStringContains( string expected, string actual,
|
---|
66 | string message )
|
---|
67 | {
|
---|
68 | if ( actual.IndexOf( expected ) < 0 )
|
---|
69 | Assert.Fail( message );
|
---|
70 | }</pre>
|
---|
71 | </div>
|
---|
72 | <p>The <b>Assert.Ignore</b> method provides you with the ability to dynamically cause a
|
---|
73 | test or suite to be ignored at runtime. It may be called in a test, setup or
|
---|
74 | fixture setup method. We recommend that you use this only in isolated cases.
|
---|
75 | The category facility is provided for more extensive inclusion or exclusion of
|
---|
76 | tests or you may elect to simply divide tests run on different occasions into
|
---|
77 | different assemblies.</p>
|
---|
78 | <p>The <b>Assert.Inconclusive</b> method indicates that the test could not be
|
---|
79 | completed with the data available. It should be used in situations where
|
---|
80 | another run with different data might run to completion, with either a
|
---|
81 | success or failure outcome.
|
---|
82 |
|
---|
83 | </div>
|
---|
84 |
|
---|
85 | <!-- Submenu -->
|
---|
86 | <div id="subnav">
|
---|
87 | <ul>
|
---|
88 | <li><a href="index.html">NUnit 2.5.10</a></li>
|
---|
89 | <ul>
|
---|
90 | <li><a href="getStarted.html">Getting Started</a></li>
|
---|
91 | <li><a href="assertions.html">Assertions</a></li>
|
---|
92 | <ul>
|
---|
93 | <li><a href="equalityAsserts.html">Equality Asserts</a></li>
|
---|
94 | <li><a href="identityAsserts.html">Identity Asserts</a></li>
|
---|
95 | <li><a href="conditionAsserts.html">Condition Asserts</a></li>
|
---|
96 | <li><a href="comparisonAsserts.html">Comparison Asserts</a></li>
|
---|
97 | <li><a href="typeAsserts.html">Type Asserts</a></li>
|
---|
98 | <li><a href="exceptionAsserts.html">Exception Asserts</a></li>
|
---|
99 | <li id="current"><a href="utilityAsserts.html">Utility Methods</a></li>
|
---|
100 | <li><a href="stringAssert.html">String Assert</a></li>
|
---|
101 | <li><a href="collectionAssert.html">Collection Assert</a></li>
|
---|
102 | <li><a href="fileAssert.html">File Assert</a></li>
|
---|
103 | <li><a href="directoryAssert.html">Directory Assert</a></li>
|
---|
104 | </ul>
|
---|
105 | <li><a href="constraintModel.html">Constraints</a></li>
|
---|
106 | <li><a href="attributes.html">Attributes</a></li>
|
---|
107 | <li><a href="runningTests.html">Running Tests</a></li>
|
---|
108 | <li><a href="extensibility.html">Extensibility</a></li>
|
---|
109 | <li><a href="releaseNotes.html">Release Notes</a></li>
|
---|
110 | <li><a href="samples.html">Samples</a></li>
|
---|
111 | <li><a href="license.html">License</a></li>
|
---|
112 | </ul>
|
---|
113 | </ul>
|
---|
114 | </div>
|
---|
115 | <!-- End of Submenu -->
|
---|
116 |
|
---|
117 |
|
---|
118 | <!-- Standard Footer for NUnit.org -->
|
---|
119 | <div id="footer">
|
---|
120 | Copyright © 2010 Charlie Poole. All Rights Reserved.
|
---|
121 | </div>
|
---|
122 | <!-- End of Footer -->
|
---|
123 |
|
---|
124 | </body>
|
---|
125 | </html>
|
---|