Build failed due to use of singleton (getInstance) in a start method

Hi,

I’m a software tester using testfx using the company internal testfx framework. I’m also a newbie to gradle and jenkins (CD/CI).

Everytime I run a build gradle to run a test, build fails. Main problem is that the class ApplicationTest I have to start the application I’m testing with, uses a getInstance() method.

This is the error message:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: >Location is not set.

The error is detected particularly on the lines where init(), getInstance() in the main application class and the use of getInstance() in my ApplicationTest class.

Excerpt from the application’s main class:

public void init(final Stage primaryStage) {
config = DisplayConfiguration.loadConfig(DisplayConfiguration.DEFAULT_PATH);
Screen scr = config.getScreen();
DEFAULT_STAGE_X = scr.getBounds().getMinX();
DEFAULT_STAGE_Y = scr.getBounds().getMinY();
instance = this;
Stage = primaryStage;
KeyboardManager.initOwner(Stage);

  boolean licensedVersion = Boolean.parseBoolean(
  		ResourceManager.getInstance().getConfigurationValue(ResourceConstants));
  if (licensedVersion) {
  	DongleManager.getInstance().addDongleStateListener(this);
  }

}

public final void start(final Stage primaryStage) {
this.init(primaryStage);
}

public static Main getInstance() {
if (instance == null) {
instance = new Main();
instance.init(new Stage());
System.out.println(“Main.getInstance()”);
}
return instance;
}

And this is my ApplicationTest class’ method looks like:

public void start(final Stage stage) {
Main.getInstance();
}

Peculiarly, if I start the test with JUnit, the application runs normally and I can see the test result (the fxrobot worked). But I need to build the test programme with gradle because the tests are supposedly to be integrated in a CD/CI, with jenkins.

I wanted to upload the build result over build scan, but I can’t because of the confidentiality of the application I’m testing.

Halp!
Thanks :smile:

PS: This is the complete error message, seen on jenkins:

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Location is not set.
at org.testfx.util.WaitForAsyncUtils.waitFor(WaitForAsyncUtils.java:302)
at org.testfx.api.FxToolkit.waitForSetup(FxToolkit.java:245)
at org.testfx.api.FxToolkit.setupApplication(FxToolkit.java:153)
at org.testfx.framework.junit.ApplicationTest.internalBefore(ApplicationTest.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:39)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:79)
at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:70)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:92)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$100(JUnitPlatformTestClassProcessor.java:77)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:73)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Location is not set.
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.testfx.util.WaitForAsyncUtils$ASyncFXCallable.get(WaitForAsyncUtils.java:697)
at org.testfx.toolkit.impl.ToolkitServiceImpl.lambda$setupApplication$6(ToolkitServiceImpl.java:127)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
… 1 more
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at Main.init(Main.java:146)
at Main.getInstance(Main.java:771)
at MainTest.start(MainTest.java:17)
at org.testfx.framework.junit.ApplicationAdapter.start(ApplicationAdapter.java:41)
at org.testfx.toolkit.impl.ApplicationServiceImpl.lambda$start$0(ApplicationServiceImpl.java:49)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
… 1 more

Hi Se. When you say you are running via JUnit, I assume you mean in your IDE? If so, can you check and let us know which version of Java, Gradle, and any dependencies you are using(if you can share that info)? Is it the same version(s) used by your CI? Also, if you using an IDE like IntelliJ, you should be able to run locally with Gradle which may help with debugging.

From experience, the singleton pattern is the root of all evil.

JUnit will use a single jvm to run multiple tests so if you initialize static variables it’s possible/probable that state from one test can “bleed” into another. You can then have the possibility that tests will pass if test A is run before test B, but will fail if B runs before A (I’m guessing this is what’s happening in your case)

Typically the singleton pattern makes sense when running your application but falls apart when running automated tests when you need to mock different scenarios

A quick fix is to have a static reset() method which cleans up any singletons (nulls them all) and reverts everything back to its an initial state. You would typically call reset() in @Before and @After methods

The “proper” fix IMHO is to remove all static mutable state (eg singletons) and embrace dependency injection / inversion of control

Further reading:

Hi Jenn, thanks for your response. Yes, what I meant was I ran the test via JUnit on the IDE (I’m using Eclipse).

I’m using Java 9, Gradle (wrapper) version 4.10, latest JUnit (jupiter and also all previous versions), the test framework developed by my colleague in a .jar file and the main application in a .jar file. Yes, I’ve checked all dependencies and these are the same version I use on my CI. I configurated also the settings on the CI.

I ran Gradle also locally (on console - Windows) and the same error message appeared.

Thank you for the information @lulu. In that case, it’s probably what @lance was talking about.

Note: You could test my theory by running a single test in Gradle via the --tests command line parameter

See java testing

I’m guessing the test will pass when run by itself but fail when run with all the other tests

Happy New Year!!!

Thanks, @Lance, I will try this right away. I’ll get back to you telling the result :slight_smile: :blush:

Hello @Lance,

I tried:

@Before
public void resetSingleton()
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
Field instance = Main.class.getDeclaredField (“instance”);
instance.setAccessible(true);
instance.set(null, null);
}

in the ApplicationTest class. And it didn’t work.

Standard error that are shown in Jenkins:

— Exception in Async Thread —

java.lang.IllegalStateException: Location is not set.

javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)

javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)

Main.init(Main.java:146)

Main.getInstance(Main.java:771)

MainTest.start(MainTest.java:27)

org.testfx.framework.junit.ApplicationAdapter.start(ApplicationAdapter.java:41)

org.testfx.toolkit.impl.ApplicationServiceImpl.lambda$start$0(ApplicationServiceImpl.java:49)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)

java.security.AccessController.doPrivileged(Native Method)

com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)

com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)

java.lang.Thread.run(Thread.java:748)

— Trace of caller of unhandled exception in Async Thread —

java.lang.Thread.getStackTrace(Thread.java:1559)

org.testfx.util.WaitForAsyncUtils$ASyncFXCallable.<init>(WaitForAsyncUtils.java:650)

org.testfx.util.WaitForAsyncUtils.asyncFx(WaitForAsyncUtils.java:258)

org.testfx.toolkit.impl.ApplicationServiceImpl.start(ApplicationServiceImpl.java:48)

org.testfx.toolkit.impl.ToolkitServiceImpl.lambda$setupApplication$6(ToolkitServiceImpl.java:127)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

java.lang.Thread.run(Thread.java:748)

— Exception in Async Thread —

java.util.concurrent.ExecutionException:

java.lang.IllegalStateException: Location is not set.

java.util.concurrent.FutureTask.report(FutureTask.java:122)

java.util.concurrent.FutureTask.get(FutureTask.java:192)

org.testfx.util.WaitForAsyncUtils$ASyncFXCallable.get(WaitForAsyncUtils.java:697)

org.testfx.toolkit.impl.ToolkitServiceImpl.lambda$setupApplication$6(ToolkitServiceImpl.java:127)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

java.lang.Thread.run(Thread.java:748)

java.lang.IllegalStateException: Location is not set.

javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)

javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)

Main.init(Main.java:146)

Main.getInstance(Main.java:771)

MainTest.start(MainTest.java:27)

org.testfx.framework.junit.ApplicationAdapter.start(ApplicationAdapter.java:41)

org.testfx.toolkit.impl.ApplicationServiceImpl.lambda$start$0(ApplicationServiceImpl.java:49)

java.util.concurrent.FutureTask.run(FutureTask.java:266)

com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)

java.security.AccessController.doPrivileged(Native Method)

com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)

com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)

java.lang.Thread.run(Thread.java:748)

— Trace of caller of unhandled exception in Async Thread —

java.lang.Thread.getStackTrace(Thread.java:1559)

org.testfx.util.WaitForAsyncUtils$ASyncFXCallable.<init>(WaitForAsyncUtils.java:650)

org.testfx.util.WaitForAsyncUtils.async(WaitForAsyncUtils.java:193)

org.testfx.toolkit.impl.ToolkitServiceImpl.setupApplication(ToolkitServiceImpl.java:123)

org.testfx.api.FxToolkit.setupApplication(FxToolkit.java:153)

org.testfx.framework.junit.ApplicationTest.internalBefore(ApplicationTest.java:86)

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:498)

org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)

org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)

org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

org.junit.runners.ParentRunner.run(ParentRunner.java:363)

org.junit.runner.JUnitCore.run(JUnitCore.java:137)

org.junit.runner.JUnitCore.run(JUnitCore.java:115)

org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:39)

java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)

java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)

java.util.Iterator.forEachRemaining(Iterator.java:116)

java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)

java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)

java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)

java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)

java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)

java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)

java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)

org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:79)

org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:70)

org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)

org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)

org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)

org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:92)

org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$100(JUnitPlatformTestClassProcessor.java:77)

org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:73)

org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:498)

org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)

org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)

com.sun.proxy.$Proxy2.stop(Unknown Source)

org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:131)

sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:498)

org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)

org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)

org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)

org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)

org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)

org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)

org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)

java.lang.Thread.run(Thread.java:748)

What should I do? :cold_sweat:

I don’t know enough about your application to know the fix, if you have one singleton it’s possible you have many.

Have you tried running the test by itself in Gradle? Does it pass?

Hi @Lance,

yes, I’ve tried running the test in Gradle. It didn’t pass, with the exact same standard error.

And yes, I have many singletons in the application. Since the application itself is made of many applications, I think there are many singletons for each subapplication. I will try implementing the dependency injection.
I’ll get back to you.

I’ve tried running the test in Gradle. It didn’t pass, with the exact same standard error.

This tells me my theory is incorrect. The error does not appear to be caused by singletons bleeding from one test to another.

If the test

  1. passes when run by itself when run in the ide
  2. fails when run by itself in Gradle

then the cause is something else.

My first thoughts would be a classpath issue where the classpath in Gradle is somehow different to the ide.

I don’t fully understand the conditions under which the test passes (your internal testfx harness). It’s possible this is doing some initialization that you’ll need to mimic in Gradle