Repository navigation
Closed
Description
Hi,
can anybody share pipeline steps to build/run tests with code coverage and test results?
Or perhaps anybody can help me modify my pipeline to support MSTestRunner?
Thanks!
This is a new project with 3.2.0 runner. What should I change in the pipeline to make it work?
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.0" />
<PackageReference Include="MSTest" Version="3.2.0" />
</ItemGroup>
</PropertyGroup>My pipeline:
- task: DotNetCoreCLI@2
displayName: Build solution
inputs:
command: "build"
projects: '**/Solution.sln'
arguments: '-c Release'
- task: DotNetCoreCLI@2
displayName: Run unit tests
continueOnError: true
inputs:
command: 'test'
projects: '**/Solution.sln'
arguments: '-c Release --results-directory "$(Build.SourcesDirectory)/TestResults/Coverage/" --collect "XPlat Code Coverage" --logger trx'
publishTestResults: false
- task: reportgenerator@5
displayName: Generate code coverage report
inputs:
reports: '$(Build.SourcesDirectory)/TestResults/Coverage/*/coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)/TestResults/CoverageReport'
- task: PublishCodeCoverageResults@1
displayName: Publish code coverage results
inputs:
codeCoverageTool: "Cobertura"
summaryFileLocation: "$(Build.SourcesDirectory)/TestResults/CoverageReport/Cobertura.xml"
reportDirectory: "$(Build.SourcesDirectory)/TestResults/CoverageReport"
- task: PublishTestResults@2
displayName: Publish test results
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/*.trx'
searchFolder: '$(Build.SourcesDirectory)/TestResults/Coverage'
mergeTestResults: true
Metadata
Metadata
Assignees
Labels
area/mtpMicrosoft.Testing.Platform core library.
Activity
Evangelink commentedon Jan 26, 2024
Hi Dimitri Kroo (@SymbioticKilla),
MSTest runner has a compatibility layer with the past so you could run your pipeline as-is (you won't get the benefit of the new features/perfs...).
If you want to take full advantage of the runner, you should be following this doc page for enabling dotnet test with the runner.
For the code coverage, if you want to use coverlet (as there is currently no specific adapter), you will have to use the global tool. Please refer to coverlet doc page https://github.com/coverlet-coverage/coverlet#net-global-tool-guide-suffers-from-possible-known-issue. If you don't mind using Microsoft Code Coverage (which we recommend - check out this article for some of the reasons https://devblogs.microsoft.com/dotnet/whats-new-in-our-code-coverage-tooling/?utm_content=buffer9eae6&utm_medium=social&utm_source=linkedin.com&utm_campaign=buffer), then you can use the following configuration.
Project
My pipeline:
SymbioticKilla commentedon Jan 27, 2024
Amaury Levé (@Evangelink)
Thank you! You are awesome!
I have changed couple of things in your proposal for pipeline:
1.) Typo fix: covertura => cobertura
--coverage-output-format cobertura2.) reportgenerator@5 => Structure for code coverage output is different. The reports folder and name are changed
3.) Disable autogenerate in PublishCodeCoverageResults@1
I have couple of questions:
1.) Is this setup that you have provided uses all (performance) improvements? Is there any refactoring that you can advise?
2.) How I can create or find sample tests to check performance improvements in the pipeline? Some sort of benchmark to show improvements in my team. Our tests are too fast (<1 Minute) I need something bigger :)
Thanks!
Evangelink commentedon Jan 28, 2024
Sorry for the missed edits and typos, I wrote by head on GH so didn't get much safetynet :(
For code coverage improvements, Jakub Chocholowicz (@jakubch1) will give you some details.
You should have it all (assuming you updated the test projects as stated in the guide).
There is one extra thing, if you are not using
MSTestmetapackage but referenceMSTest.TestAdapterandMSTest.TestFrameworkthen please addMSTest.Analyzersand I strongly suggest enabling the[assembly: Parallelize(Scope = ExecutionScope.Method)](once again by head on GH so there might be a typo). For now, MSTest runs tests in sequence by default and not in parallel. This would be the best and biggest perf improvement you can do :)You can add the
--no-restoreand--no-buildarguments on yourdotnet testcall (see https://learn.microsoft.com/dotnet/core/tools/dotnet-test#options) as you have a separate build step.It depends how big you want, but you can refer to our samples of performance diff between VSTest and MSTest runner (https://github.com/microsoft/testfx/tree/main/samples/runner_vs_vstest#mstest-runner-vs-vstest)
jakubch1 commentedon Jan 29, 2024
Dimitri Kroo (@SymbioticKilla) for code coverage please check those examples: https://github.com/microsoft/codecoverage/tree/main/samples/Algorithms
All of them include Azure DevOps pipeline definition.
SymbioticKilla commentedon Jan 29, 2024
Thank you!
I have tried to check performance. It is weird... With a new MSTest Runner the tests are slower.
We are using .NET7, but I have also tried with .NET8.
Build Agents are linux based.
1.) Test step with a new MS Test Runner in Azure Devops:
/_work/_tool/dotnet/dotnet test /_work/11/s/Source/Solution.sln --no-restore --no-build -c Release -p:TestingPlatformCommandLineArguments= --results-directory "/_work/11/s/TestResults/Coverage/" --report-trx --coverage --coverage-output-format coberturaExecution time: ~12 seconds
2.) Test step with an old VSTest
/_work/_tool/dotnet/dotnet test /_work/18/s/Source/Solution.sln --no-restore --no-build -c Release --results-directory /_work/18/s/TestResults/Coverage/ --collect XPlat Code Coverage --logger trxExecution time: ~6 Seconds
New tests .csproj:
nohwnd commentedon Jan 30, 2024
Could you please share a bit more detail about your solution? (Unless it is opensource and you can just link me to your repo :)) I would like to investigate this, but we only heard about one similar issue that is using a custom ITestDataSource, and there we still don't know the cause because it is huge and super hard to build.
ITestDataSource, inherited attributes from[TestMethod]or[TestClass]?You could also create a VS feedback ticket (https://developercommunity.visualstudio.com/home) and privately attach any logs that you can collect, or a subset of your solution that reproes the issue.
collecting logs of runner: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-runner-extensions#built-in-options
collecting logs of VSTEST: https://github.com/microsoft/vstest/blob/main/docs/diagnose.md
Evangelink commentedon Jan 30, 2024
Jakub Jareš (@nohwnd) I think he just setup some CI using the perf samples we have in the repo:
nohwnd commentedon Jan 31, 2024
I've tried this on my local windows system, and I am seeing 6 seconds on my trivial test solution with 2 projects and 2 tests (in total), when coverlet is enabled.
Are you running the old command against the same solution as the new one? The new solution does not have coverlet installed in the project, and so the whole overhead of coverage is skipped.
My proj for comparison
Old + coverlet: ~7s
Old without coverlet: ~3s
New with coverage: ~3s
New without coverage: ~2.5s
Old + coverlet:
Old without coverlet
new with coverage:
new without coverage
SymbioticKilla commentedon Jan 31, 2024
Thanks for testing!
I have tested with our project inside pipeline. I can't share the code :(
I will check it locally and try your benchmark test projects as well.
I hope I can do it this week.
nohwnd commentedon Jan 31, 2024
Thanks, it would be helpful if you shared sanitized output of the build, if possible.
9 remaining items
nohwnd commentedon Feb 6, 2024
Dimitri Kroo (@SymbioticKilla) We found the issue. We are hooking up to the VSTest target, which dotnet/sdk allows us to replace. In the original VStest task we conditionally build the tested project (to allow dotnet build -t:vstest, to work). In our new target we copied this approach, but forgot this condition, so every project will "build" again. "build" in quotes because it invokes msbuild, that does up-to-date check and returns, but it still takes a second or more per project.
We will release a fix for this soon.
SymbioticKilla commentedon Feb 6, 2024
Glad to hear! Waiting to test 👍
Evangelink commentedon Feb 6, 2024
Update: This is full guide to accessing our preview packages: https://aka.ms/mstest/preview
Dimitri Kroo (@SymbioticKilla) would you be interested in testing the fix before its release? If so, you could use the following feed https://github.com/microsoft/testfx/blob/main/NuGet.config#L8. I'll get back to you with the min version that contains the fix.
Evangelink commentedon Feb 8, 2024
Closing as done. We will reopen if there is still some issue for you.
Evangelink commentedon Feb 13, 2024
Dimitri Kroo (@SymbioticKilla) MSTest 3.2.1 was just released
SymbioticKilla commentedon Feb 15, 2024
Amaury Levé (@Evangelink)
Works perfect! x2 faster!
I have just one regression with Microsoft.Testing.Extensions.TrxReport 1.0.1 on build agent (linux):
/root/.nuget/packages/microsoft.testing.platform.msbuild/1.0.1/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets(225,5): error : Tests failed: '/_work/20/s/TestResults/Coverage/Project.Tests_net7.0_x64.log' [net7.0|x64]
On windows (locally) is not reproducible.
1.0.0 works as expected. Should I create a new bug report?
Evangelink commentedon Feb 15, 2024
Love it!
Oh sorry! Yes please do! Could you try to provide some extra info about the project? Can you for example send me (by email or through developer community - please follow that link for how to upload private info https://learn.microsoft.com/cpp/overview/how-to-report-a-problem-with-the-visual-cpp-toolset?view=msvc-170#reports-and-privacy) the TRX that was produced before?
I suspect there is something badly handled related to a fix we did on TRX for another customer.
nohwnd commentedon Feb 15, 2024
I don't see the trx fail for my almost empty project when running under WSL. So that is a plus (that it does not fail always).
SymbioticKilla commentedon Feb 17, 2024
Jakub Jareš (@nohwnd) Amaury Levé (@Evangelink)
Hi,
I can reproduce it locally on my windows machine. You need to specify --results-directory:
dotnet test Solution.sln -c Release --no-build --no-restore -d verbose -p:TestingPlatformCommandLineArguments="--results-directory "dev/TestResults/" --report-trx --coverage --coverage-output-format cobertura "
The error: Unhandled exception. System.IO.IOException: The file 'C:\dev\TestResults\userName_PCName_2024-02-17_11_30_43.trx' already exists.
With 1.0.0 it produces correctly all .trx files with milliseconds in the name. With 1.0.1 it produces same milliseconds values so the files have the same name. I have 4 test projects and it is a little bit random => 1+ projects succeed and other get the error.