.NET Core单元测试未在AppVeyor测试窗口及徽章中显示
I’ve run into exactly this issue before! The core problem is that AppVeyor can’t parse plain console output to populate the test window or update the shields.io badge — it needs structured test reports in a format it recognizes (like xUnit/JUnit XML). Here’s how to fix it step by step:
1. Ensure Your Test Projects Generate XML Reports
First, make sure your test project references the Microsoft.NET.Test.Sdk NuGet package (this is a required dependency for generating structured test reports in .NET Core). Then, modify your dotnet test command to explicitly output an XML report.
For xUnit tests, use this command (adjust the project path and output location as needed):
dotnet test YourTestProject.csproj --configuration Release --logger "xunit;LogFilePath=../TestResults/test-results.xml"
If you’re using NUnit, swap the logger type:
dotnet test YourTestProject.csproj --configuration Release --logger "nunit;LogFilePath=../TestResults/test-results.xml"
For multiple test projects, generate unique report files (e.g., test-results-MyFirstTests.xml, test-results-MySecondTests.xml) to avoid overwriting, and use a wildcard later to pick them all up.
2. Configure AppVeyor to Pick Up the Reports
Update your appveyor.yml to tell AppVeyor where to find the generated XML reports. Add this section:
test: assemblies: - '**/TestResults/*.xml'
Alternatively, you can use the test_report directive for more explicit control:
test_report: '**/TestResults/*.xml'
This tells AppVeyor to scan all TestResults folders for XML reports and parse them to populate the test window, count total tests, and update the shields.io badge.
3. Verify the Setup
Run a new build and check the AppVeyor logs:
- Look for lines confirming the XML report was generated (e.g.,
Results File: C:\projects\your-repo\TestResults\test-results.xml) - Check the "Tests" tab in AppVeyor — you should now see the full list of tests, their statuses, and total count.
- The shields.io badge should also update to reflect the correct number of tests once the build completes successfully.
If you still run into issues, double-check:
- The path to the test report is correct (AppVeyor runs commands from the repo root by default, so relative paths should be adjusted accordingly)
- Your test project has all required NuGet packages (like
xunit.runner.visualstudiofor xUnit, orNUnit3TestAdapterfor NUnit) - The XML report is actually being generated (check the build artifacts or log for the file existence)
内容的提问来源于stack exchange,提问作者Sergio0694

