1

I've got some basic automated GUI tests for my Java desktop application that work when running on my Windows desktop. On GitHub they fail with

java.awt.AWTError at X11GraphicsEnvironment.java:-2

I started from the default Java CI with Gradle workflow, and have added some steps attempting to set up xvfb so it has a display to work with, but it's still failing. Is there a way I can modify the workflow so that X11 is available for the tests?

name: Java CI with Gradle

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'
    - name: Set up virtual X11
      run: sudo apt-get install xvfb
    - name: Start virtual frame buffer
      run: Xvfb :19 -screen 0 1024x768x16 &
    - name: set display
      run: export DISPLAY=:19
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build
Brad Mace
  • 27,194
  • 17
  • 102
  • 148

1 Answers1

0

I ended up splitting the GUI tests off using JUnit @Tags, and then adding separate gradle tasks:

task nonGuiTest(type: Test) {
    useJUnitPlatform {
        excludeTags 'gui'
    }
}

task guiTest(type: Test) {
    useJUnitPlatform {
        includeTags 'gui'
    }
}

then in the workflow

  • I run build -x test initially
  • then run the non-GUI tests
  • then use the GabrielBB/xvfb-action@v1 action to set up xvfb
  • then run the GUI tests
name: Java CI with Gradle

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build -x test
    - name: headless tests
      run: ./gradlew nonGuiTest
    - name: GUI tests
      uses: GabrielBB/xvfb-action@v1
      with:
        run: ./gradlew guiTest
Brad Mace
  • 27,194
  • 17
  • 102
  • 148