I have a Tomcat application that uses the process builder to run some system commands. For example chattr
. These are wrapped in hyper methods such as follows:
public static void lockFile(String file) {
if ("Linux".equals(getOS()))
executeCmd("/usr/bin/chattr +i " + file, 0);
}
Most of our developers use windows machines however our application is deployed in either Debian, Ubuntu or FreeBSD environments.
Is there a way to run tests in Junit5 that will let me control the OS my code is being run on?
I have tests using TestContainers already but use that for providing run time dependencies such as a database, not something that my code is injected into.
I also looked into the annotation EnabledOnOs
but that would just restrict what environments our tests are run on. As most developers use windows this would mean our tests could not be run locally.
Is there any facility to do this? I’d like to get coverage on these tests in a way that uses minimal mocking. I could just mock out the backend calls, but that seems brittle ( assume my mocks accidentally returned slightly different results or an environment we deploy to changes.