简体   繁体   中英

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

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 .

Seems like there is no solution to do so right now.

Here is ticket for rider: https://youtrack.jetbrains.com/issue/RIDER-38942 and for visual studio: https://developercommunity.visualstudio.com/t/allow-running-unit-tests-in-docker/554907

There are some hacks, which you can do to attach debugger to test project, but all of them require some manual interaction and experience is not as seamless as running/debugging the application.

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

For .NET development use Squadron . It orchestrate docker to spin up the container with given resource (Redis is supported) and clean up after test execution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM