Vstest: How to execute .NET Core unit tests?

Created on 6 Jul 2018  路  2Comments  路  Source: microsoft/vstest

Description

I started to configure my release workflow to execute my .NET Core unit tests, something I thought would be super-easy with the VSTest task + the VSTest Platform installer. However, it turns out to be quite complex in my case.
I need some advice in hot to set it up correctly.

Steps to reproduce

My environment is configured w/o Visual Studio. Hence, I'm using the VSTest Platform Installer task.
I have one test project, developed in .NET Core 2.1, using the 15.8.0-preview-20180610-02 of the SDK.
When I first executed I got an FileNotFoundException, but I saw an issue that explained that you need to deploy a published build of the test project, which I have done now. Is this needed?
However, still the tests aren't executed. When running the tests, the log says:

2018-07-06T14:07:29.2617957Z Starting test execution, please wait...
2018-07-06T14:07:29.4469067Z Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X86. Following DLL(s) do not match framework/platform settings.
2018-07-06T14:07:29.4469591Z MyTest.Tests.dll is built for Framework 2.1 and Platform AnyCPU.

And then no tests are discovered in the file.

  • How should the tasks be configured to execute my .NET Core tests?
  • Is a published project really needed?
  • Is it better to install full Visual Studio on the agent?

Most helpful comment

OK, I did some reading and saw that you need to use the "Other console options" configuration, and supply "/Framework:FrameworkCore10" for it to execute .NET Core Tests. However, the link the tooltip referenced https://msdn.microsoft.com/en-us/library/jj155796.aspx?f=255&MSPPError=-2147217396, which says nothing about "FrameworkCore10".
Also, using "FrameworkCore10" gives an error saying that we're testing the wrong version, so the correct setting is ".NETCoreApp,Version=v2.1".

All 2 comments

Update: running manually on the environment with vstest.console.exe MyTest.Tests.dll works. So it must be some configuration in the task that I'm missing. It's not that clear however.

OK, I did some reading and saw that you need to use the "Other console options" configuration, and supply "/Framework:FrameworkCore10" for it to execute .NET Core Tests. However, the link the tooltip referenced https://msdn.microsoft.com/en-us/library/jj155796.aspx?f=255&MSPPError=-2147217396, which says nothing about "FrameworkCore10".
Also, using "FrameworkCore10" gives an error saying that we're testing the wrong version, so the correct setting is ".NETCoreApp,Version=v2.1".

Was this page helpful?
0 / 5 - 0 ratings