A green check mark is worth only as much as the check behind it. In this lesson, you make the Kladde's check honest: it shows which tests ran and what they cover; it turns red when a test is red, when none runs at all and when a package has a known security hole; and it doesn't stay stuck on old packages.
Making test results visible
So far, the result of the tests sits only in the log of the "Test" step. With three tests, that's enough; with three hundred, it isn't: whoever wants to know which test is red searches through hundreds of lines. Better is a test report, a file that the pipeline's tools read and display.
The Kladde's test projects use xUnit 3 on the Microsoft.Testing.Platform. xUnit brings reports in several formats, which you switch on
with options after the --:
--report-xunit-trxwrites a report in the TRX format, Visual Studio's test format. Azure Pipelines reads it.--report-xunit-markdownwrites a short summary in Markdown that you can show on a run's page at GitHub.
dotnet test --solution Kladde.slnx --configuration Release --no-build --results-directory TestResults -- --report-xunit-trx --report-xunit-markdown
In process file artifacts produced:
- …/TestResults/<user>_<machine>_<date>_<time>.md
- …/TestResults/<user>_<machine>_<date>_<time>.trx
Test run summary: Passed!
total: 2
failed: 0
succeeded: 2
skipped: 0
duration: 1s 411ms
The files get a name made of user, machine and time, so yours will be different. That's a good thing: each test project writes its own
reports into the same TestResults folder, and unique names keep one from overwriting another. So don't specify a fixed file name
(--report-xunit-trx-filename) as long as the Kladde has more than one test project.
--results-directory TestResults sets the folder explicitly. Newer SDKs use this folder as the default anyway, while older ones put the
reports in the output folder of each test project; with the option, it doesn't matter which SDK happens to be building on the runner.
If a test is red, the Markdown summary names it along with its message:
### Test Results
⌚ 273ms total run time
🧪 2 tests
✅ 1 passed
❌ 1 failed
#### Failed ❌
* Kladde.Core.Tests.BookingRulesTests.BookingsThatTouchDoNotOverlap ⌚ 0.021s
_Exception:_
```
Assert.True() Failure
Expected: True
Actual: False
```