Search code examples
c#visual-studiotestingnunit

Is it possible to run tests in Visual Studio just to produce output?


I have a little problem. I am doing tests in Visual Studio using NUnit, and I would love to have an option to run all tests without actually running them, just for producing something into tests output. I mean, every test have a Description attribute, and I have even created one myself called HumanName and I am writing them to Output using TestContext.Write() method. So when the tests runs, everybody can see Description and HumanName values. I am also writing some other things, like parametrized or non-parametrized data used in the test.

So when the tests runs, all these things are beautifully writing to Output, but I would love to have all these things to be written to Output even before running Tests, for example during build.

And so I had this idea, that I would just create one static bool somewhere, and then I put a method into each test, let's call it FinishTestWhenRunningJustForWritingOutput, which runs if the static bool variable is set to true, and won't run if it is set to false. And I put this method call at the beginning of each test, and it would finish the test without executing any TestSteps and it could actually even set Test Result to "Not Run". Then it would create Test Output even without actually running tests :)

So to be able to implement this idea, I would love to know if it is possible to:

  1. Halt test execution programatically in some other way than by throwing Exception
  2. Set Test Result to "Not Run" programatically

Thanks sooo much for any help, I would greatly appreciate it :)


Solution

  • I've found it. Just use Assert.Inconclusive(); It will finish test and mark it as Inconclusive, which is fine, I don't need the test to be marked as Not Run. Inconclusive is fine :)