-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Consider a system property to conditionally initialize LottieTask.EXECUTOR for testing #2612
Description
Is your feature request related to a problem? Please describe.
When running Paparazzi-based snapshot tests on the JVM we have to set LottieTask.EXECUTOR to a direct executor. This requires that every test class whose test functions interact with Lottie perform this act somewhere, be it a @Before, @BeforeClass, a @Rule, or static block.
If every test does not do this, running a subset of tests can fail as no one has changed the value yet.
Describe the solution you'd like
I would like the static initializer to check a system property and conditionally set a direct executor itself. This would allow us to set a system property on the entire Test task which would globally control this behavior for all tests regardless of the order or subset that is run.
Something like
public static Executor EXECUTOR;
static {
if ("true".equals(System.getProperty("lottie.testing.directExecutor"))) {
EXECUTOR = Runnable::run;
} else {
EXECUTOR = Executors.newCachedThreadPool(new LottieThreadFactory());
}
}Describe alternatives you've considered
- Custom JUnit runner to set the value. While this works on Android unit tests executed under instrumentation, Gradle does not allow overriding the runner for JVM-based unit tests.
- Switching to a different test framework. Seems unreasable to port thousands of tests just to get a hook into initialization before the tests run.