|
87 | 87 | <h1 id="repeat">Repeat</h1> |
88 | 88 |
|
89 | 89 | <p><strong>RepeatAttribute</strong> is used on a test method to specify that it should be |
90 | | -executed multiple times. If any repetition fails, the remaining ones are |
91 | | -not run and a failure is reported.</p> |
92 | | -<h2 id="notes">Notes</h2> |
93 | | -<ol> |
94 | | -<li>If RepeatAttribute is used on a parameterized method, each individual |
95 | | -test case created for that method is repeated.</li> |
96 | | -<li>It is not currently possible to use RepeatAttribute on a TestFixture |
97 | | -or any higher level suite. Only test cases may be repeated.</li> |
98 | | -</ol> |
| 90 | +executed multiple times.</p> |
| 91 | +<p>By default, the test is repeated until a failure occurs. If no failures occur, it runs for the specified number of repetitions.</p> |
| 92 | +<p>You can change this behavior in case of a failure, so that it continues to run after the failure by setting the property <code>StopOnFailure</code> to <code>false</code>. (From version 4.3.0)</p> |
99 | 93 | <h2 id="examples">Examples</h2> |
100 | | -<pre><code class="lang-csharp">[Test] |
101 | | -[Repeat(25)] |
102 | | -public void MyTest() |
| 94 | +<h3 id="the-default-behavior">The default behavior</h3> |
| 95 | +<pre><code class="lang-csharp" name="RepeatDefaultAttributeExample">[Test] |
| 96 | +[Repeat(5)] |
| 97 | +public void TestMethod1() |
103 | 98 | { |
104 | | - /* The contents of this test will be run 25 times. */ |
| 99 | + Assert.Pass(); |
| 100 | +} |
| 101 | +</code></pre><h3 id="run-all-regardless-of-failures">Run all regardless of failures</h3> |
| 102 | +<pre><code class="lang-csharp" name="RepeatWithFaultAttributeExample"> |
| 103 | +private int count2 = 0; |
| 104 | + |
| 105 | +[Test,Explicit] // Marking the test as Explicit to avoid failing our doc build. You can skip this. |
| 106 | +[Repeat(5, StopOnFailure = false)] |
| 107 | +public void TestMethod3() |
| 108 | +{ |
| 109 | + count2++; |
| 110 | + Assert.That(count2, Is.Not.EqualTo(3)); // Intentional failure on 3rd iteration |
105 | 111 | } |
106 | 112 | </code></pre> |
| 113 | +<div class="WARNING"> |
| 114 | +<h5>Warning</h5> |
| 115 | +<p>There is currently (as of 4.4.0) a <a href="https://github.com/nunit/nunit/issues/5031">bug</a> which causes only the last successful console statement to be output. Also, in case of failures, only the latest failure is shown.</p> |
| 116 | +</div> |
| 117 | +<div class="NOTE"> |
| 118 | +<h5>Note</h5> |
| 119 | +<p>If RepeatAttribute is used on a parameterized method, |
| 120 | +each individual test case created for that method is repeated. |
| 121 | +It is not currently possible to use RepeatAttribute on a TestFixture or any higher level suite. Only test cases may be repeated.</p> |
| 122 | +</div> |
107 | 123 |
|
108 | 124 | </article> |
109 | 125 | </div> |
|
0 commit comments