nusCS2113-AY1819S1 / forum

5 stars 0 forks source link

Travis throws an exception: java.awt.HeadlessException #105

Closed DarylTew closed 5 years ago

DarylTew commented 5 years ago

So even though my CurrentCommandTest (my command is called Current) runs and passes on Intellij, Travis throws me an error: java.awt.HeadlessException: No X11 DISPLAY variable was set, but this program performed an operation which requires it. See below: image

This is how my code is: image

Does anyone know how to fix this?

okkhoy commented 5 years ago

@DarylTew did you manage to get this working?

DarylTew commented 5 years ago

No I can't unfortunately. This only occurs for the tests when there is a success outcome.

damithc commented 5 years ago

Does the test work when run using gradle, in headless, mode on your computer?

DarylTew commented 5 years ago

The test works using gradle i think.

pyokagan commented 5 years ago

Some background information:

So you have two options:

  1. Make Travis run an X server (search for xvfb). Note that this is by definition not "headless" according to AB-4's definition since you are actually creating windows, moving the mouse etc.

  2. Follow TestFX's "headless" approach and mock out any GUI operations.

pyokagan commented 5 years ago

Alternatively, stick to JavaFX and not use Swing.

DarylTew commented 5 years ago

image Hi thanks for your reply, are you referring to this for option 1? And what do you mean by your note?

DarylTew commented 5 years ago

Oh and do you know why this happens only at this test? Surely there are other tests which are quite similar?

yamgent commented 5 years ago

Hi thanks for your reply, are you referring to this for option 1?

Most likely yes.

And what do you mean by your note?

By default, Travis is set up to run in headless mode (see the executed command inside .travis.yml):

travis_retry ./gradlew clean checkstyleMain checkstyleTest headless allTests coverage coveralls asciidoctor copyDummySearchPage

If you were to configure Travis to use xvfb, then you are techincally no longer using headless. I am not sure whether this requires you to turn headless mode off for Travis (turning on xvfb may not have an effect otherwise), so you will have to play around with it and give it a try.

Oh and do you know why this happens only at this test? Surely there are other tests which are quite similar?

I only had a quick glance at your team's repo, so I may be wrong, but as far as I can tell, CurrentCommand is the only class around that are using awt and swing stuff. Everything else is using javafx.

If time permits, or if the xvfb is not working as expected and you really need it to work on Travis, I suggest re-looking at the implementation of CurrentCommand.

DarylTew commented 5 years ago

Thank you all for your help!