简体   繁体   中英

How do I run Unit Tests for .NET Framework 4.7 with Travis-CI?

I try to run the tests for my project in Travis-CI . My project is structured like this:

.
|-- src (.NET Framework 4.7 class library)
|-- test (.NET Core 3.1 unit test project using MSTest)

I can't change the project in ./src to .NET core.

My .travis.yml looks like this:

language: csharp
mono: none
dotnet: 3.1.200
before_install: cd test
script:
  - dotnet restore
#  - dotnet add package Microsoft.NETFramework.ReferenceAssemblies.net47 --version 1.0.0
  - dotnet test /p:CollectCoverage=true

The second line in the script is something I tried but it didn't help.

It would be great if anyone could lead me to a solution for this. Or tell me that this doesn't work.

So after quite a while I got it working.

The .travis.yml has to look like this:

language: csharp
mono: latest
dotnet: 3.1.200
before_install:
  - cd src
script:
  - dotnet restore
  - msbuild
  - dotnet test ../tests/bin/Debug/netcoreapp3.1/tests.dll

Explanation:

  • We need .Net Core to build the tests .NET Core project and Mono to build the src .NET 4.7 project.
  • It's not possible to use dotnet build to build the .NET 4.7 project, instead the msbuild command from Mono has to be used.
  • The dotnet test command does only work, if the path to the tests.dll is provided

Additional notes:

  • Mono takes a lot of time to install (~7 minutes), which makes the builds slow. Maybe it's worth to look into using the mono docker container instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM