-
Notifications
You must be signed in to change notification settings - Fork 722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to extract a list of tests cases and their categories programmatically. #3627
Comments
Hi, Next I tried the NUnit engine api (scroll down a bit to see an example) and it worked for the nunit projects targeting dotnet framework, but I ran into issues loading dependencies for projects targeting dotnet core, but of course YMMV. In the end I realised it would be nice if my solution also worked for test solutions using other unit testing frameworks so created a custom vstest test logger which I use along with the nunit3testadapter. The custom logger defines event handlers for the Another alternative could be using vstest.console.exe and the NUnit3Adapter, and enabling the DumpXmlTestDiscovery adapter setting. However the dump is diagnostic info so its not really a public API and I suppose it could change. I haven't tried it but you should be able to use the same vstest.console.exe command line trick shown above to enable the dumpxmltestdiscovery option from the command line: That solution may be a bit over the top for your needs, but it ended up not being much code at all. It just requires consumers to be using vstest version 16 or above. I can't remember off the top of my head, but I think the categories were 'flattened'. References:
[edit] updated the example usage - I had included the incorrect runconfiguration property |
The Xml from the DumpXmlTestDiscovery for the test output itself (!) comes directly from the NUnit Engine, and is not likely to change in itself. This is the same Xml information that the adapter uses, so any change is this would require a new adapter, and would break backwards compatibility, something we are very careful about. However, the file in itself will be expanded, so your code should take that into consideration. Grabbing the test discovery output nodes however, should be perfectly safe. |
Hello @shack05 and @OsirisTerje , Thanks a lot for your insights! To recap all the solutions:
...
ITestEngine engine = TestEngineActivator.CreateInstance();
I will probably end up mixing 1 and 3. |
Hello Folks,
This is a question.
I am trying to get a list of all the test cases and their respective categories.
Currently I see three options:
Reflection: going through all methods, check for TestAttribute/TestCaseAttribute/TestFixture...
Using a runner, extract the xml with runner.Explore and parse the xml.
Use what NUnit is already doing.
My question revolves around the latter:
How to "flatten" the categories for each testcase? (when categories are put on abstract class or the whole class)
Ideally I would like to reuse what is already in use in NUnit to extract its test list.
Any suggestion as to where to start reading ?
Best regards,
Simon
The text was updated successfully, but these errors were encountered: