Search code examples
visual-studiounit-testingdockervisual-studio-2017xunit

Unit Tests in Visual Studio Tools for Docker?


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?


Solution

  • 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.