I run unit and integration tests on my system. These create, start, stop and delete Docker containers. I want the exact same state in my Docker environment at the end of the tests as I had at the beginning. What would be the best way to restore the original state after the tests run?
Option A: I create a class in the main code that stops and deletes docker containers that were created and executed by the app, which is then also used by the tests.
Option B: I have an abstract class/interface in my main code which is extended/implemented by all classes that need to stop and delete. I create an extra class/method in test code which stops and deletes docker containers.
Option C,D,E,...: ???
In general, does it make sense to create classes in the main code that are specifically designed to be used within the tests, but also by the main code. In my example: classes that can be used after testing to clean up the Docker environment, but also in the main code for the same purpose. Or should this be separated, even if this results in duplicate code when implemented in main and test, but the implementation in main code would be cleaner (e.g. better OO style)?
Is there anything against creating classes/methods in the main code that are mainly used for tests?