0

I am trying to run an all included exe (created using Costura ) on a windows VM. As per an answer in this SO question , I have installed test agent and build tools and trying to run exe through this command

C:\Users\..\Desktop>"C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" MyExeName.exe /Tests: MyTestName

on VM , I start the agent and give above command but I am receiving error No test is available in C:\Users\..\Desktop\MyExeName.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

The exe runs fine on local machine using same command and start tests. On local I have VS2019 and all the code. On VM , I can not have VS and code base as a requirement.

EDIT: I noticed (through ILSpy) that in dot exe under references, there is no reference to this Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll , however the dll is present in resources.

user1207289
  • 3,060
  • 6
  • 30
  • 66
  • Anyone on this please? – user1207289 Feb 04 '20 at 14:17
  • You could use the /ListDiscoverers and /ListExecutors arguments to find the test discoverer and executors on the VM. Just to rules some things out. https://learn.microsoft.com/en-us/visualstudio/test/vstest-console-options?view=vs-2019#general-command-line-options – Kevin Feb 04 '20 at 20:10
  • @Kevin When I run that , I do not see `Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter` package, however I see `Default Executor Uri: executor://mstestadapter/v1` but package listed for this is different `Microsoft.VisualStudio.TestPlatform.Extensions.VSTestIntegration.MSTestDiscoverer` – user1207289 Feb 04 '20 at 20:23
  • So it seems that reference to `Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter` is indeed the issue for not discovering tests. How can I include that reference and not break it when create an exe, any idea? – user1207289 Feb 04 '20 at 20:30
  • Try to add MSTest.TestAdapter as a package https://www.nuget.org/packages/MSTest.TestAdapter/ – Kevin Feb 05 '20 at 06:15
  • @Kevin , thanks for your response . When I compared the out put of this command `vstest.console.exe MyExeName.exe \ListExecutors \ListDiscoverers ` for local and the VM (where I am having issue) , it looks same. In that sense, it seems it is not a referencing issue. Can you think of anything else , why I cant run exe on VM through `vstest.console` – user1207289 Feb 05 '20 at 15:16
  • How does your output folder look like on the VM? Your platform is set to 'Any Cpu'? Are you using the same framework version on your local machine as on the VM? – Kevin Feb 05 '20 at 15:30
  • @Kevin I am not sure how to check out put folder because , I am running an exe (created by Costura.Fody package) on VM. Yes, when I build/create exe , I see that platform is set 'Any CPU' . I checked, I have .NET Framework 4.8 on both local and VM. And my solution is targeting Framework 4.7.2 in project properties – user1207289 Feb 05 '20 at 16:02
  • Do you think it has to do something with test agent and test controller setup? When I started , I installed Test Agent and Build Tools as per an answer in [this](https://stackoverflow.com/questions/3402899/can-i-use-mstest-exe-without-installing-visual-studio) . I am able to run command though, using `vstest.console` located here `C:\Program Files (x86)\Microsoft Visual Studio\2017\T estAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe` – user1207289 Feb 05 '20 at 16:14
  • Can you share your test class? I will install a test agent on my VM so I can check it out. – Kevin Feb 05 '20 at 20:54

1 Answers1

0

I could reproduce this error... I did some experiments on my csproj file and it turns out you have to add an Import tag in your console csproj file. This has nothing to do with your test agent or test class.

Check your package.config (ps. this is 2019, so check your version) MSTest.TestAdapter has to be added.

<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net48" />

Secondly, add the Import tag to your csproj file. (and again check your version)

<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />

ProjectFile

When importing this project a few more items are being added to your project.

Props

And this results into this output

Output

See screenshots below for test case 1 (not working) and 2 (working)

Test 1: Test1

Test 2: Test2

I hope this is working on your end!!

Solution and project: solution

Kevin
  • 506
  • 6
  • 13
  • I was able to get past that error by help from [this](https://stackoverflow.com/questions/26629647/no-xunit-tests-discovered-by-vstest-console-exe) i.e by passing /TestAdapterPath in command line. However , I would like to not pass that parameter and somehow build everything into exe. As per your answer , I looked and both of these lines are already there in my project. `` – user1207289 Feb 06 '20 at 15:26
  • And `` , If you have any idea how to build everything into exe , I would be glad to accept answer :) – user1207289 Feb 06 '20 at 15:27
  • My answer was based on only a console application. I will update my answer with a screenshot of my solution. – Kevin Feb 06 '20 at 15:30