VSTS build of .NET Core 1.0 VSTest Warning: No tes

2019-05-05 18:47发布

问题:

I recently switched all of my unit tests over from xunit to mstest, and on my local dev machine everything works great, but when I try to run my tests using a CI build in VSTS, it doesn't recognize any tests in my test dll, stating:

"Warning: No test is available in c:\vsts_work\4\s\test\UnitTests\bin\Release\net452\UnitTests.dll".

I believe I have all of the important project.json bits in place:

  "testRunner": "mstest",

  "dependencies": {
    "dotnet-test-mstest": "1.0.1-preview",
    "MSTest.TestFramework": "1.0.1-preview"
  }

Of note, I am using an on-premise build agent, but I've proven I can log into that build agent using the service account under which the agent runs, and I can open visual studio and run the tests that way.

Also, while one could contrive it by looking at the above path, it is worth explicitly noting that I'm using the full framework.

Hoping someone out there has already conquered this one.

回答1:

I figured out how to use the "Visual Studio Test" action, thanks to this stackoverflow post

The only thing that answer lacks is how to make it work in VSTS (the answer provides the command line). To get it to work in VSTS, I put the following string in the "Test Assembly" parameter

**\test\**\project.json

And then put the rest of the command line arguments under "Advanced Execution Options" in the "Other console options" box.

/UseVsixExtensions:true /logger:trx

Hope this helps the next guy who is trying to stick with the visual studio tooling.



回答2:

To run a .NET Core test during the build, you can add a "Command Line" task to run "dotnet test" command and set the "Working Folder" to the path where the "project.json" file placed:



回答3:

I had a similar problem, getting the "Warning: No test is available" issue when I was looking right at the tests in Visual Studio. It turns out the tests were trying to run in x86 when the application is 64 bit.

I recommend going to the Test menu at the top of Visual Studio, and open

Test>Test Settings>Default Processor Architecture>

and make sure the tests are on the right architecture, if you have a similar problem and the other answers aren't helping.