unit testing - Why is the xUnit Runner not finding my tests -


i have xunit.net test follows:

static class mytestclass {     [fact]     static void mytestmethod()      {     } } 

the xunit plugin vs 2012 says:

no tests found run.

testdriven.net runs fine but mentions ad hoc:

1 passed, 0 failed, 0 skipped (see 'task list'), took 0.47 seconds (ad hoc)

teamcity, xunit.gui.exe , xunit.console.exe , visual studio can't find testmethod

(i've got xunit.runner.visualstudio installed , vs seeing tests.)

what gives?

tl;dr test classes must public (but test methods can private and/or static)


for reasons of efficiency, xunit authors have opted not use bindingflags.nonpublic when searching test classes in runner (the msil metadata tables don't index private(/internal) classes same degree hence there significant performance difference in relative efficiency reflection can achieve).

as result of above, fact class private means doesn't picked up.

the fact test method private , static fine - xunit design since 1.0 has supported both aspects.

note visual studio xunit runner extension, xunit.console.exe (and gui), xunit msbuild task, resharper , coderush consistent in honouring (although arguably [especially latter two] more flag when test class (i.e. class [potentially indirectly] containing fact-derived annoations) private).

the reason testdriven.net runs test author of testdriven.net has put great effort making work. internally uses special test runner wrapper/shim (termed adhoc runner) run test. aware method not being run via xunit.net runner , hence attributes put on test have side effects not triggered.

notably nunit (and i'm pretty sure mstest) do use private reflection [and hence pick tests in private classes] why never seemed important thing worry before.

note: side effect / trick enabled can make test class private quick way of skipping tests in test class [and nested classes]. (sadly cases on planet of being used unintentionally vastly outnumber intentional cases of though!)


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -