mark
mark

Reputation: 62712

How to get the number of tests without running them and with minimum text parsing using vstest.console.exe?

I have the following command line working:

dotnet vstest ...\Platform.UnitTests.dll -lt

And it does show the available tests:

Microsoft (R) Test Execution Command Line Tool Version 15.9.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The following Tests are available:
    UnitTests.KeyGenerationTests.GenerationServiceTests.GenerateLongTest(min: -9223372036854775807, max: 3722052250456372)
    UnitTests.KeyGenerationTests.GenerationServiceTests.GenerateLongTest(min: 0, max: 2818886159009824)
    UnitTests.KeyGenerationTests.GenerationServiceTests.GenerateLongTest(min: 1234, max: 3070940396521188)
    UnitTests.KeyGenerationTests.GenerationServiceTests.GenerateLongTest(min: -4544123, max: 6717503777496228)

So, I can get the count with the following Powershell command line:

(dotnet vstest ...\Platform.UnitTests.dll -lt | Select-Object -Skip 4 | Measure-Object -Line).Lines

But is it the best way?

E.g. with NUnit I can get an xml file listing all the test cases and counting certain nodes (using XPath) gives us the count of NUnit test cases. I like this one much more, because it does not require me to parse the command output.

So, the question is - can we get the count of tests with vstest.console.exe without parsing the output?

P.S.

Purists might indicate that reading XML involves parsing it. I am fine with that kind of parsing.

Upvotes: 1

Views: 720

Answers (1)

Francis Dean
Francis Dean

Reputation: 2476

To clarify: not a full answer, but, in my case I wanted to find a way of checking for an absence of tests as part of an Azure DevOps pipeline (using dotnet test as part of a bash script).

dotnet test MySolution.sln --list-tests --verbosity=quiet --nologo | wc -l

The flags I used were list-tests to display the list of tests, verbosity=quiet and nologo flag (for good measure) to hide the junk, and piped the output into linux wordcount (wc), with the -l flag to count the number of lines.

This results in an output of 0 if there are no tests. If there are tests, then the count will be wrong as there is still some verbose output -therefore this solution will not offer a count of tests as per the questions, but may help anyone who stumbles across this question (as I did) whilst looking to check for a lack of tests.

Upvotes: 1

Related Questions