VSTS自动化构建中单元测试未执行的技术求助
Hey there, let's figure out why your VsTest task is starting but not executing any unit tests. Based on the log snippet you shared, here are the most common issues to check and fix:
Double-check test assembly matching patterns
The defaulttestAssembliespattern (**\*test*.dll;-:**\*TestAdapter.dll;-:**\obj\**) might not match your test project's output DLL. If your test assemblies are named like*Tests*.dllor follow a different convention, update the "Test files" field in the VsTest task to explicitly target them, e.g.,**\bin\$(BuildConfiguration)\*Tests.dll.
To confirm if your test DLLs exist at the expected path, add a temporary Command Line task to run:dir $(Build.SourcesDirectory) /s /b *test*.dllThis will list all matching DLLs in your build workspace.
Ensure test projects are being built
Sometimes test projects are excluded from the build configuration. Go to your solution's properties, verify that the test project is checked under the current build configuration (e.g.,$(BuildConfiguration)). Also, check the build logs for entries likeBuilding project "C:\agent\_work\1\s\YourTestProject\YourTestProject.csproj"—if you don't see this, the test DLL isn't being generated at all.Align VsTest task configuration with build settings
Make sure the "Platform" and "Configuration" parameters in the VsTest task match exactly what your build task uses. For example, if your build targetsx64andRelease, the VsTest task should use the same values—mismatched settings will lead to the task looking in the wrong folder for test assemblies.
Also, uncheck the "Skip test runs if no test assemblies are found" option temporarily. If the task can't find any assemblies, this will throw an error instead of silently skipping, which helps pinpoint the issue.Verify test adapter compatibility
If you're using third-party test frameworks like NUnit or xUnit, ensure the corresponding test adapter NuGet package is installed in your test project:- For NUnit:
NUnit3TestAdapter - For xUnit:
xunit.runner.visualstudio
Outdated or missing adapters will prevent the VsTest task from discovering your tests.
- For NUnit:
Review the full VsTest task logs
The snippet you shared only shows the task start. Expand all log entries for the VsTest task—you'll likely find detailed messages like "No test assemblies found matching the pattern" or errors loading test assemblies, which are critical for troubleshooting.
内容的提问来源于stack exchange,提问作者Philipp

