Skip to content

Commit c409428

Browse files
committed
Add information to explicit tests (#1017)
* Add information to explicit tests * Add information to explicit tests * Add information to explicit tests * update * Linting fixes * Auto-fix markdownlint issues --------- Co-authored-by: Sean Killeen <[email protected]> e41eb5b
1 parent 9863165 commit c409428

File tree

3 files changed

+731
-715
lines changed

3 files changed

+731
-715
lines changed

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

+22-6
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,24 @@ <h2 id="examples-of-use">Examples of Use</h2>
115115
<pre><code class="lang-none"> --where test!=My.Namespace.Fixture
116116
--where cat!=X
117117
</code></pre>
118+
<h2 id="trap">TRAP</h2>
119+
<p>If a project contains only explicit tests, running the test project will execute all tests, as it is treated as an
120+
explicit test run. To prevent this, ensure the project includes at least one non-explicit test, even if it's just a
121+
dummy test.</p>
122+
<p>From <a href="https://github.com/nunit/nunit3-vs-adapter/issues/1223">this issue</a>, the following comment explains how the
123+
adapter works with explicit tests:</p>
124+
<p><em>&quot;When the adapter is called from the testhost, it receives a list of tests to run. It doesn't know HOW the Test
125+
Explorer is being used. And thus it has no knowledge if there are other tests present that are not selected, OR if the
126+
tests it receives are all the tests in the solution.</em></p>
127+
<p><em>If all the tests are Explicit it will assume that this is an explicit testrun. When you only have one test, and that
128+
test is explicit, it will be an explicit test run.</em></p>
129+
<p><em>When you add the second test, which is not explicit, it will see both tests, and since there is a non-explicit test
130+
included, the test is a non-explicit testrun, and all explicit tests will be ignored.</em></p>
131+
<p><em>If you have a situation with only one explicit test, the work around is to just add another non-explicit test, which
132+
can be empty, or even have a false Assume statement, which will make the test be inconclusive, thus not part of your
133+
results.&quot;</em></p>
118134
<h2 id="test-fixture-syntax">Test Fixture Syntax</h2>
119-
<h3 id="c"><code>C#</code></h3>
135+
<p>C#:</p>
120136
<pre><code class="lang-csharp">namespace NUnit.Tests
121137
{
122138
using System;
@@ -129,7 +145,7 @@ <h3 id="c"><code>C#</code></h3>
129145
}
130146
}
131147
</code></pre>
132-
<h3 id="visual-basic">Visual Basic</h3>
148+
<p>Visual Basic:</p>
133149
<pre><code class="lang-VB">Imports System
134150
Imports NUnit.Framework
135151

@@ -141,7 +157,7 @@ <h3 id="visual-basic">Visual Basic</h3>
141157
End Class
142158
End Namespace
143159
</code></pre>
144-
<h3 id="c-1">C++</h3>
160+
<p>C++:</p>
145161
<pre><code class="lang-cpp">using namespace System;
146162
using namespace NUnit::Framework;
147163

@@ -162,7 +178,7 @@ <h3 id="c-1">C++</h3>
162178
}
163179
</code></pre>
164180
<h2 id="test-syntax">Test Syntax</h2>
165-
<h3 id="c-2"><code>C#</code></h3>
181+
<p>C#:</p>
166182
<pre><code class="lang-csharp">namespace NUnit.Tests
167183
{
168184
using System;
@@ -176,7 +192,7 @@ <h3 id="c-2"><code>C#</code></h3>
176192
{ /* ... */ }
177193
}
178194
</code></pre>
179-
<h3 id="visual-basic-1">Visual Basic</h3>
195+
<p>Visual Basic:</p>
180196
<pre><code class="lang-vb">Imports System
181197
Imports NUnit.Framework
182198

@@ -189,7 +205,7 @@ <h3 id="visual-basic-1">Visual Basic</h3>
189205
End Class
190206
End Namespace
191207
</code></pre>
192-
<h3 id="c-3">C++</h3>
208+
<p>C++:</p>
193209
<pre><code class="lang-cpp"># using &lt;NUnit.Framework.dll&gt;
194210
using namespace System;
195211
using namespace NUnit::Framework;

index.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@
29622962
"articles/nunit/writing-tests/attributes/explicit.html": {
29632963
"href": "articles/nunit/writing-tests/attributes/explicit.html",
29642964
"title": "Explicit | NUnit Docs",
2965-
"keywords": "Explicit The Explicit attribute causes a test or test fixture to be skipped unless it is explicitly selected for running. The test or fixture will be run if it is selected by name or if it is included by use of a filter. A not filter, which excludes certain tests, is not treated as an explicit selection and never causes an explicit test to be run. All other filters are considered to explicitly select the tests that they match. See examples below. An optional string argument may be used to give the reason for marking the test Explicit. If a test or fixture with the Explicit attribute is encountered in the course of running tests, it is skipped unless it has been specifically selected by one of the above means. The test does not affect the overall result of the test run. Explicit tests are displayed in the gui as skipped. Warning While the C# syntax allows you to place an Explicit attribute on a SetUpFixture class, the attribute is ignored by NUnit and has no effect in current releases. Examples of Use Using the console command-line to select tests, the following options will include any explicit tests that fall under the selection. --test=My.Namespace.Fixture.Method --test=My.Namespace.Fixture --test=My.Namespace --where test==My.Namespace.Fixture.Method --where test==My.Namespace.Fixture --where test==My.Namespace --where cat==X --where \"cat==X || cat==Y\" However, the following options will not include explicit tests --where test!=My.Namespace.Fixture --where cat!=X Test Fixture Syntax C# namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture, Explicit] public class ExplicitTests { // ... } } Visual Basic Imports System Imports NUnit.Framework Namespace NUnit.Tests <TestFixture(), Explicit()> Public Class ExplicitTests ' ... End Class End Namespace C++ using namespace System; using namespace NUnit::Framework; namespace NUnitTests { [TestFixture] [Explicit] public __gc class ExplicitTests { // ... }; } # include \"cppsample.h\" namespace NUnitTests { // ... } Test Syntax C# namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture] public class SuccessTests { [Test, Explicit] public void ExplicitTest() { /* ... */ } } Visual Basic Imports System Imports NUnit.Framework Namespace NUnit.Tests <TestFixture()> Public Class SuccessTests <Test(), Explicit()> Public Sub ExplicitTest() ' ... End Sub End Class End Namespace C++ # using <NUnit.Framework.dll> using namespace System; using namespace NUnit::Framework; namespace NUnitTests { [TestFixture] public __gc class SuccessTests { [Test][Explicit] void ExplicitTest(); }; } # include \"cppsample.h\" namespace NUnitTests { // ... }"
2965+
"keywords": "Explicit The Explicit attribute causes a test or test fixture to be skipped unless it is explicitly selected for running. The test or fixture will be run if it is selected by name or if it is included by use of a filter. A not filter, which excludes certain tests, is not treated as an explicit selection and never causes an explicit test to be run. All other filters are considered to explicitly select the tests that they match. See examples below. An optional string argument may be used to give the reason for marking the test Explicit. If a test or fixture with the Explicit attribute is encountered in the course of running tests, it is skipped unless it has been specifically selected by one of the above means. The test does not affect the overall result of the test run. Explicit tests are displayed in the gui as skipped. Warning While the C# syntax allows you to place an Explicit attribute on a SetUpFixture class, the attribute is ignored by NUnit and has no effect in current releases. Examples of Use Using the console command-line to select tests, the following options will include any explicit tests that fall under the selection. --test=My.Namespace.Fixture.Method --test=My.Namespace.Fixture --test=My.Namespace --where test==My.Namespace.Fixture.Method --where test==My.Namespace.Fixture --where test==My.Namespace --where cat==X --where \"cat==X || cat==Y\" However, the following options will not include explicit tests --where test!=My.Namespace.Fixture --where cat!=X TRAP If a project contains only explicit tests, running the test project will execute all tests, as it is treated as an explicit test run. To prevent this, ensure the project includes at least one non-explicit test, even if it's just a dummy test. From this issue, the following comment explains how the adapter works with explicit tests: \"When the adapter is called from the testhost, it receives a list of tests to run. It doesn't know HOW the Test Explorer is being used. And thus it has no knowledge if there are other tests present that are not selected, OR if the tests it receives are all the tests in the solution. If all the tests are Explicit it will assume that this is an explicit testrun. When you only have one test, and that test is explicit, it will be an explicit test run. When you add the second test, which is not explicit, it will see both tests, and since there is a non-explicit test included, the test is a non-explicit testrun, and all explicit tests will be ignored. If you have a situation with only one explicit test, the work around is to just add another non-explicit test, which can be empty, or even have a false Assume statement, which will make the test be inconclusive, thus not part of your results.\" Test Fixture Syntax C#: namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture, Explicit] public class ExplicitTests { // ... } } Visual Basic: Imports System Imports NUnit.Framework Namespace NUnit.Tests <TestFixture(), Explicit()> Public Class ExplicitTests ' ... End Class End Namespace C++: using namespace System; using namespace NUnit::Framework; namespace NUnitTests { [TestFixture] [Explicit] public __gc class ExplicitTests { // ... }; } # include \"cppsample.h\" namespace NUnitTests { // ... } Test Syntax C#: namespace NUnit.Tests { using System; using NUnit.Framework; [TestFixture] public class SuccessTests { [Test, Explicit] public void ExplicitTest() { /* ... */ } } Visual Basic: Imports System Imports NUnit.Framework Namespace NUnit.Tests <TestFixture()> Public Class SuccessTests <Test(), Explicit()> Public Sub ExplicitTest() ' ... End Sub End Class End Namespace C++: # using <NUnit.Framework.dll> using namespace System; using namespace NUnit::Framework; namespace NUnitTests { [TestFixture] public __gc class SuccessTests { [Test][Explicit] void ExplicitTest(); }; } # include \"cppsample.h\" namespace NUnitTests { // ... }"
29662966
},
29672967
"articles/nunit/writing-tests/attributes/fixturelifecycle.html": {
29682968
"href": "articles/nunit/writing-tests/attributes/fixturelifecycle.html",

0 commit comments

Comments
 (0)