From: David Roden Date: Sun, 11 May 2025 08:42:24 +0000 (+0200) Subject: ✅ Add @GuiTest annotation for tests that require a GUI X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=55d2c516876d0c19e8484aedb09e547bee95401b;p=msta.git ✅ Add @GuiTest annotation for tests that require a GUI --- 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(); + } + +}