Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping a whole test class in xUnit.net

Tags:

c#

xunit.net

Is it possible to skip all tests from a specific class like in NUnit

[TestFixture] [Ignore("Reason")] public class TestClass { } 
like image 978
dwonisch Avatar asked Feb 12 '13 19:02

dwonisch


People also ask

How do I skip a test in xUnit?

xUnit.net does not require an attribute for a test class; it looks for all test methods in all public (exported) classes in the assembly. Set the Skip parameter on the [Fact] attribute to temporarily skip a test.

Do xUnit tests run in order?

Ordering classes and casesTests are executed in ascending order. If no Order attribute is specified default 0 is assigned. Multiple Order attributes can have same value.

Does xUnit create a new class for each test?

xUnit.net creates a new instance of the test class for every test that is run, so any code which is placed into the constructor of the test class will be run for every single test.

Do xUnit tests run in parallel?

Running unit tests in parallel is a new feature in xUnit.net version 2. There are two essential motivations that drove us to not only enable parallelization, but also for it to be a feature that's enabled by default: As unit testing has become more prevalent, so too have the number of unit tests.


1 Answers

No - there is no such facility at present,

One quick way of achieving the effect in xUnit is to comment out the public - private classes are not reflected over (obviously it won't appear on the skip list that way though).

Consider logging it as an Issue on CodePlex if you feel the need for this is sufficiently common (I personally can't imagine upvoting it as I simply don't run into cases where I need to skip an entire Test Class worth of tests).

UPDATE: Another way is to put a TraitAttribute on the class and then (assuming you're using the xunit.console runner) filter it out by running with /-trait traitName. (e.g. you can achieve ExplicitAttribute, some aspects of the BDD frameworky technique of Pending tests and similar semantics that way - of course the big problem is they don't show up in any reports when using any of these filtering techniques)

UPDATE 2: You can do

const string skip = "Class X disabled";  [Fact(Skip=skip)] void Test() {} 

Then you can change to to const string skip = null to undo the skip. The (dis)advantage of this is that the test is still shown as a Skipped test in the test list, generally with a reason included in the test run report (vs making it private which makes it likely to be forgotten)

like image 109
Ruben Bartelink Avatar answered Sep 19 '22 22:09

Ruben Bartelink