How to run tests in rider / visual studio in docker container

Viewed 744

My integration tests have dependency on redis. They have dockerfile included, so everything works in CI. However when running locally from test explorer I have to manually start redis container.

Is there possibility for IDE to automatically run/debug tests in docker containers, so when attemptying to run/debug test in IDE (or maybe even using dotnet test) everything runs in docker?

Please note, that I want to run/debug tests in docker, not docker in tests.

2 Answers

Why not run the container manually?

  1. Install docker to the local machine.
  2. Use Docker.DotNet nuget in your test project to work with the docker api.
  3. Stop all containers.
  4. Start the containers you need from your code manually.
  5. Run the tests and clear the state after every one.

Such a way you will get a working environment after the tests (all containers will be running).

Related