Unit Tests in Visual Studio Tools for Docker?
Asked Answered
C

1

18

Is it currently possible (and if so, how) to run unit tests from Visual Studio in Docker and get the results in the Test Explorer?

I am having success using Visual Studio Tools for Docker and writing tests, both through XUnit and Microsoft's TestTools. However, there doesn't seem to be a way (that I can see) to run the tests inside a docker container. I can go through the effort of setting up a docker image myself, but is there something already available?

Crinkleroot answered 6/10, 2017 at 12:34 Comment(1)
Currently it's a feature request you can upvote here : developercommunity.visualstudio.com/idea/554907/…Bloodletting
S
1

This might come a little late, but this can now be done using the Remote Testing functionality that is available in Visual Studio starting from version 17.5.

As stated in the documentation, you'll need to configure your test environments first.

To run your tests on a Docker container, your testEnvironments.json file may look as follows:

{
  "version": "1",
  "environments": [
    {
      "name": "Docker dotnet/sdk",
      "type": "docker",
      "dockerImage": "mcr.microsoft.com/dotnet/sdk"
    }
  ]
}

The nicest part is that you can keep managing and running your tests from the Test Explorer as Visual Studio is taking care of spinning the Docker container for you.

You'll also need to make sure your local Docker daemon is running.

Stewpan answered 24/4, 2023 at 20:16 Comment(1)
This looks like what I was hoping for! I haven't tried it yet (I am not working on the same project anymore), but I'm going to mark this as the answer because, per the documentation, it seems correct! Thanks!Crinkleroot

© 2022 - 2024 — McMap. All rights reserved.