Zettelkasten-Team / Zettelkasten

Zettelkasten-Developer-Builds
http://zettelkasten.danielluedecke.de
GNU General Public License v3.0
737 stars 94 forks source link

Headless Environment Error in AutoBackupTaskTest #510

Closed RalfBarkow closed 6 months ago

RalfBarkow commented 6 months ago

We encountered an issue while running the AutoBackupTaskTest test case. The test fails with a HeadlessException due to the absence of an X11 DISPLAY variable. This issue arises in environments where a graphical display is not available, such as CI pipelines or headless servers.

Error Log:

Error:  Errors: 
Error:    AutoBackupTaskTest.setUp:44 » Headless 
No X11 DISPLAY variable was set,
but this program performed an operation which requires it.
[INFO] 
Error:  Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

Steps to Reproduce:

  1. Run the test suite in a headless environment (e.g., a CI pipeline or a server without a graphical display).
  2. Observe the error in the AutoBackupTaskTest test case.

Expected Behavior: The test should either pass without requiring a graphical display or be skipped in headless environments.

Possible Solutions:

  1. Use Headless Mode: Ensure that tests are run in headless mode by setting the java.awt.headless property to true in the test configuration.

    System.setProperty("java.awt.headless", "true");

    This can be done in the test setup method:

    @Before
    public void setUp() {
       System.setProperty("java.awt.headless", "true");
       // other setup code
    }
  2. Skip Tests in Headless Environment: Modify the test to check if the environment is headless and skip the test if it is:

    @Before
    public void setUp() {
       if (GraphicsEnvironment.isHeadless()) {
           System.out.println("Skipping test in headless environment");
           return;
       }
       // other setup code
    }

Additional Context: This issue prevents the test suite from running successfully in headless environments, impacting the CI pipeline's ability to validate changes.