Skip to content

Commit 01a7c95

Browse files
committed
Merge pull request #1071 from nunit/repeatAttribute
Updated doc on repeat attribute 473bcc4
1 parent 7086085 commit 01a7c95

File tree

3 files changed

+753
-737
lines changed

3 files changed

+753
-737
lines changed

articles/nunit/writing-tests/attributes/repeat.html

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,39 @@
8787
<h1 id="repeat">Repeat</h1>
8888

8989
<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>
9993
<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()
10398
{
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
105111
}
106112
</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>
107123

108124
</article>
109125
</div>

index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,7 @@
31123112
"articles/nunit/writing-tests/attributes/repeat.html": {
31133113
"href": "articles/nunit/writing-tests/attributes/repeat.html",
31143114
"title": "Repeat | NUnit Docs",
3115-
"summary": "Repeat RepeatAttribute is used on a test method to specify that it should be executed multiple times. If any repetition fails, the remaining ones are not run and a failure is reported. Notes If RepeatAttribute is used on a parameterized method, each individual test case created for that method is repeated. It is not currently possible to use RepeatAttribute on a TestFixture or any higher level suite. Only test cases may be repeated. Examples [Test] [Repeat(25)] public void MyTest() { /* The contents of this test will be run 25 times. */ }"
3115+
"summary": "Repeat RepeatAttribute is used on a test method to specify that it should be executed multiple times. By default, the test is repeated until a failure occurs. If no failures occur, it runs for the specified number of repetitions. You can change this behavior in case of a failure, so that it continues to run after the failure by setting the property StopOnFailure to false. (From version 4.3.0) Examples The default behavior [Test] [Repeat(5)] public void TestMethod1() { Assert.Pass(); } Run all regardless of failures private int count2 = 0; [Test,Explicit] // Marking the test as Explicit to avoid failing our doc build. You can skip this. [Repeat(5, StopOnFailure = false)] public void TestMethod3() { count2++; Assert.That(count2, Is.Not.EqualTo(3)); // Intentional failure on 3rd iteration } Warning There is currently (as of 4.4.0) a bug which causes only the last successful console statement to be output. Also, in case of failures, only the latest failure is shown. Note If RepeatAttribute is used on a parameterized method, each individual test case created for that method is repeated. It is not currently possible to use RepeatAttribute on a TestFixture or any higher level suite. Only test cases may be repeated."
31163116
},
31173117
"articles/nunit/writing-tests/attributes/requiresthread.html": {
31183118
"href": "articles/nunit/writing-tests/attributes/requiresthread.html",

0 commit comments

Comments
 (0)