.NET Core Unit tests not shown in AppVeyor Tests window (and badge)
Asked Answered
S

3

10

Follow up from this question, I'm currently setting up AppVeyor for my project (here) and my .NET Core tests are only shown in the console output but not in the Tests window.

This is the link for the AppVeyor project: ci.appveyor.com/project/Sergio0694/neuralnetwork-net

If some tests fail, the console correctly shows an error and the build is marked as failing, but the Tests window is empty anyways. Same goes for the badge from shields.io which shows 0 total tests, even if I can see many of them being executed from the console output.

Here's the console output: enter image description here

And here's the Tests window: enter image description here

Is there something else I have to setup in order for them to be reported correctly outside the console window?

Salutation answered 12/1, 2018 at 23:23 Comment(0)
H
9

Please add https://www.nuget.org/packages/Appveyor.TestLogger to your test projects.

Homogeneous answered 12/1, 2018 at 23:39 Comment(4)
I added this package to the test project, but the executed tests are still not reflected in the AppVeyor UI (ci.appveyor.com/project/Viir/kalmit/build/1.0.7)Haunt
You will need to update the line where you call dotnet test . here with the following: dotnet test --test-adapter-path:. --logger:Appveyor reference: github.com/spekt/appveyor.testloggerRipe
Thank you for the pointer @Adriang. Confirm, adding ` --test-adapter-path:. --logger:Appveyor` resulted in the test results surfacing in AppVeyor UI, including text output.Haunt
Works fine but seems like my Unit Tests "duplicates" here's the link to appveyor build, logs say that 28 tests were passed but in tests I see that there are 38 tests instead of 28Darwen
R
8

An arguably cleaner alternative to adding an otherwise unused reference to your test project is to do this in your test script:

cd <test_project_dir>
nuget install Appveyor.TestLogger -Version 2.0.0
cd ..
dotnet test --no-build --no-restore --test-adapter-path:. --logger:Appveyor <test_project_dir>

This has the same effect as adding the reference, in that it makes the testlogger binary available to the test framework, but it doesn't actually change the test project, and therefore doesn't require someone who's not using Appveyor to install the package when they clone and build your repo.

The slight advantage of this solution over outputting and subsequently uploading .trx files (as in the PS script above) is that you should get the test results in real-time, rather than all at the end.

Example appveyor.yml:

version: 0.0.{build}
build_script:
- cmd: dotnet build MySolution.sln
test_script:
- cmd: cd Test
- cmd: nuget install Appveyor.TestLogger -Version 2.0.0
- cmd: cd ..
- cmd: dotnet test --no-build --no-restore --test-adapter-path:. --logger:Appveyor Test
Recapitulate answered 14/11, 2018 at 21:32 Comment(1)
U can do it without 'cd', just nuget install Appveyor.TestLogger and run dotnet test ...Hillegass
S
2

You can add the AppVeyor.TestLogger package to your project, but it can be done without changing your code. You need to output your tests results into an xml file format that AppVeyor understands and then upload it to their HTTP API. The following powershell snippet will iterate through your solution and find each test project, call dotnet test on the csproj and log the output to test-result.trx and then upload the file to AppVeyor.

$config = "release"

# Find each test project and run tests and upload results to AppVeyor
Get-ChildItem .\**\*.csproj -Recurse | 
    Where-Object { $_.Name -match ".*Test(s)?.csproj$"} | 
    ForEach-Object { 

        # Run dotnet test on the project and output the results in mstest format (also works for other frameworks like nunit)
        & dotnet test $_.FullName --configuration $config --no-build --no-restore --logger "trx;LogFileName=..\..\test-result.trx" 

        # if on build server upload results to AppVeyor
        if ("${ENV:APPVEYOR_JOB_ID}" -ne "") {
            $wc = New-Object 'System.Net.WebClient'
            $wc.UploadFile("https://ci.appveyor.com/api/testresults/mstest/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test-result.trx)) 
        }

        # don't leave the test results lying around
        Remove-Item .\test-result.trx -ErrorAction SilentlyContinue
}
Sigil answered 27/2, 2018 at 22:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.