From 55d2c516876d0c19e8484aedb09e547bee95401b Mon Sep 17 00:00:00 2001 From: David Roden Date: Sun, 11 May 2025 10:42:24 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20@GuiTest=20annotation=20for=20?= =?utf8?q?tests=20that=20require=20a=20GUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++++ test/pom.xml | 34 ++++++++++++++++++ .../main/java/de/qsheltier/msta/test/GuiTest.java | 42 ++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 test/pom.xml create mode 100644 test/src/main/java/de/qsheltier/msta/test/GuiTest.java diff --git a/pom.xml b/pom.xml index 4508734..934eca5 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,11 @@ ${project.version} + de.qsheltier + msta-test + ${project.version} + + org.junit junit-bom 5.11.3 @@ -149,5 +154,6 @@ server client + test diff --git a/test/pom.xml b/test/pom.xml new file mode 100644 index 0000000..cb296c6 --- /dev/null +++ b/test/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + + de.qsheltier + msta + 0.1-SNAPSHOT + + + msta-test + + MSTA – Test + Manual Software Testing Avoidance – Testing Component + + + + de.qsheltier + msta-client + + + org.junit.jupiter + junit-jupiter-api + compile + + + org.hamcrest + hamcrest + compile + + + + diff --git a/test/src/main/java/de/qsheltier/msta/test/GuiTest.java b/test/src/main/java/de/qsheltier/msta/test/GuiTest.java new file mode 100644 index 0000000..a817ee8 --- /dev/null +++ b/test/src/main/java/de/qsheltier/msta/test/GuiTest.java @@ -0,0 +1,42 @@ +package de.qsheltier.msta.test; + +import java.awt.GraphicsEnvironment; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.condition.DisabledIf; + +/** + * Annotation for a test that requires a GUI toolkit to be available. + * If no GUI toolkit is available (as per {@link IsHeadless#isHeadless()}, + * tests annotated with this annotation are skipped. + */ +@Inherited +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Tag("gui") +@DisabledIf("de.qsheltier.msta.test.IsHeadless#isHeadless") +public @interface GuiTest { +} + +/** + * Helper for JUnit’s {@link DisabledIf}, to determine if {@link GuiTest}s + * should be run. + */ +@SuppressWarnings("unused") +class IsHeadless { + + /** + * Returns {@code true} if not GUI toolkit is available. + * + * @return {@code true} if no GUI toolkit is available, + * {@code false} otherwise + */ + public static boolean isHeadless() { + return GraphicsEnvironment.isHeadless(); + } + +} -- 2.7.4