I have a few UI tests for my Java application made with AssertJ-Swing and JUnit 5. I encounter no problem running these tests locally but some of the tests fail once I push them to my continuous integration on Github Actions.
The .yml
looks like this:
...
jobs:
build:
runs-on: ubuntu-latest
env:
workdir: idTest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Build with Maven
run: >
xvfb-run mvn verify
working-directory: ${{ env.workdir }}
As you can see I'm using xvfb-run
to run the tests headlessly and for my simple tests that should be enough.
Dumb example test that (sometimes) fails because the item is not selected:
@Test
@GUITest
void test() {
Item item = new Item("name");
GuiActionRunner.execute(() -> view.getListModel().addElement(item));
window.list("list").selectItem(0);
window.list("list").requireSelectedItems(0);
}
The "strange" thing is that sometimes the test passes and sometimes it doesn't. It happens also with click()
on buttons.
I've also tried running the tests under Windows (that needs no xvfb
to run) on Github Actions with no problems, so I guess that xvfb
is the issue here.
Anyone knows what the problem might be? I'm also up for trying different solutions other than xvfb
if anyone has any suggestions. Thanks.