Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to test when headless? #63

Open
i-make-robots opened this issue Nov 1, 2023 · 0 comments
Open

how to test when headless? #63

i-make-robots opened this issue Nov 1, 2023 · 0 comments

Comments

@i-make-robots
Copy link

Hello, I hope you are well.

I hope this is the right area for this issue.

I've been up and down the assertj swing documentation and I don't see any mention of how to run headless unit tests. My specific case is that I want to test my JPanel interaction results. I tried the following:

public class PaperSettingsPanelTest extends AssertJSwingJUnitTestCase {
	private JPanelFixture panel;

	@Override
	protected void onSetUp() {
		PreferencesHelper.start();
		Translator.start();
		panel = new JPanelFixture(robot(),new PaperSettingsPanel(new Paper()));
	}

	@SuppressWarnings("unlikely-arg-type")
	@Test
	public void testLandscapeToPortrait() {
		panel.comboBox("size").selectItem(1);
		assert(panel.textBox("width.field").equals("1682"));
		assert(panel.textBox("height.field").equals("2378"));
		panel.comboBox("size").selectItem(1);
		panel.checkBox("landscape").click();
		assert(panel.textBox("width.field").equals("2378"));
		assert(panel.textBox("height.field").equals("1682"));
	}
}

and I get

java.lang.ExceptionInInitializerError
	at org.assertj.swing.monitor.WindowMonitor.instance(WindowMonitor.java:143)
	at org.assertj.swing.core.BasicRobot.<clinit>(BasicRobot.java:123)
	at org.assertj.swing.testing.AssertJSwingTestCaseTemplate.setUpRobot(AssertJSwingTestCaseTemplate.java:36)
	at org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase.setUp(AssertJSwingJUnitTestCase.java:48)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
Caused by: java.awt.HeadlessException
	at java.desktop/sun.java2d.HeadlessGraphicsEnvironment.getScreenDevices(HeadlessGraphicsEnvironment.java:52)
	at org.assertj.swing.util.RobotFactory.newRobotInLeftScreen(RobotFactory.java:52)
	at org.assertj.swing.monitor.WindowStatus.<init>(WindowStatus.java:57)
	at org.assertj.swing.monitor.WindowStatus.<init>(WindowStatus.java:50)
	at org.assertj.swing.monitor.WindowMonitor.<init>(WindowMonitor.java:60)
	at org.assertj.swing.monitor.WindowMonitor$SingletonLazyLoader$1.executeInEDT(WindowMonitor.java:151)
	at org.assertj.swing.monitor.WindowMonitor$SingletonLazyLoader$1.executeInEDT(WindowMonitor.java:148)
	at org.assertj.swing.edt.GuiQuery.run(GuiQuery.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch$$$capture(InvocationEvent.java:318)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
	at org.assertj.swing.edt.GuiActionRunner.execute(GuiActionRunner.java:98)
	at org.assertj.swing.monitor.WindowMonitor$SingletonLazyLoader.<clinit>(WindowMonitor.java:148)
	... 29 more


java.lang.NullPointerException: Cannot invoke "org.assertj.swing.core.Robot.cleanUp()" because "this.robot" is null

	at org.assertj.swing.testing.AssertJSwingTestCaseTemplate.cleanUp(AssertJSwingTestCaseTemplate.java:43)
	at org.assertj.swing.junit.testcase.AssertJSwingJUnitTestCase.tearDown(AssertJSwingJUnitTestCase.java:82)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	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.RunAfters.evaluate(RunAfters.java:33)
	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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)

This happens with both IntelliJ IDEA running the tests on my desktop (?!) and Maven lifecycle tests.

fwiw the project is https://github.com/MarginallyClever/Makelangelo-software and the test case is src/test/java/com/marginallyclever/makelangelo/paper/PaperSettingsPanelTest.java

Can someone please give me a hint how to do this right? I have a lot of panels that could use tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant