I'd like to report them before they're run, and have the option to run individual tests through shell scripts without managing categories. We have some unmanaged code which can leave the process in a bad state, and sometimes are happy to run each test individually per nunit-console run.
相关问题
- Interface from a C DLL to .NET
- Partial Code Coverage C# - Nunit
- Expect exceptions in nUnit without the ExpectedExc
- How can I output results of tests ran with NUnit 3
- How to copy a array of unmanaged memory into the s
相关文章
- Passing struct from unmanaged C++ to C#
- How to set the value of a query string in test met
- How to unit-test a class which needs a specific fi
- How do I ignore a test based on another test in NU
- How is it that a struct containing ValueTuple can
- Test projects not reading app.config in TeamCity -
- How can I display more info in an error message wh
- Dependencies not flowing between dependent project
nunit-console still doesn't seem to support this option. It is however fairly straightforward to get a list of the test cases using reflection. At a very basic level, you want a list of all
public
methods of anypublic class
with the appropriate[Test]/[TestFixture]
attributes. Depending upon how your tests are structured, you might need to do additional filtering, such as to remove any tests marked up with[Ignore]
attributes or to consider test methods in base classes.At a basic level, the code would look something like this:
Obviously you'd be able to streamline this a bit if you only wanted the test methods from a particular
TestFixture
.As has been said in the comments, this gets a bit more complicated if you need to pay attention to other NUnit attributes, such as
TestCase
andTestCaseSource
. I've modified the code below to support some of the functionality of these attributes.If you look through the code above, you might notice that I've handled functionality where the
TestCaseSource
for tests is a string naming the property/method/field. You'll also notice that whilst there is more code, it's still pretty straightforward code, so it could be easily extended if you were using an alternative version of the TestCaseSource, or if there are other NUnit attributes you're using that I haven't catered for.It would also be easy enough to add a counter to the above so that you had a level of comfort that the same number of tests were printed as the number of tests that nunit-console would be running.
There is now the
--explore
command-line option that can be used to list all test cases without running tests. More specificallyFor more info: https://github.com/nunit/docs/wiki/Console-Command-Line#description