From ff00885682c4814fa97da1c2ff09d6059d9153f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A4rtschi=20Robin?= Date: Thu, 6 Jun 2024 22:23:29 +0200 Subject: [PATCH] Begin testing --- build.gradle.kts | 24 ++++++++++++++++++- gradle.properties | 2 +- .../environmenttech/EnvironmentTech.java | 2 ++ .../environmenttech/test/TestMain.java | 17 +++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 src/test/java/robaertschi/environmenttech/test/TestMain.java diff --git a/build.gradle.kts b/build.gradle.kts index b5cd7fb..11011eb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { idea `maven-publish` id("io.freefair.lombok") version "8.6" - id ("net.neoforged.gradle.userdev") version ("7.0.138") + id ("net.neoforged.gradle.userdev") version ("7.0.139") } val minecraftVersion: String by project @@ -58,6 +58,10 @@ runs { modSource (project.sourceSets["main"]) } + create("junit") { + junit(true) + } + create("client") { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. systemProperty ("forge.enabledGameTestNamespaces", modId) @@ -82,6 +86,7 @@ runs { // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. programArguments.addAll ("--mod", modId, "--all", "--output", file("src/generated/resources/").absolutePath, "--existing", file("src/main/resources/").absolutePath) } + } // Include resources generated by data generators. @@ -91,6 +96,15 @@ sourceSets.main.configure { } } +sourceSets { + test { + java { + srcDir("src/test/java") + } + resources{ srcDir("src/test/resources")} + } +} + dependencies { // Specify the version of Minecraft to use. @@ -101,6 +115,10 @@ dependencies { // For all intends and purposes: You can treat this dependency as if it is a normal library you would use. implementation ("net.neoforged:neoforge:${neoVersion}") + // Testing + testImplementation(platform("org.junit:junit-bom:5.10.2")) + testImplementation("org.junit.jupiter:junit-jupiter-params") + // Example mod dependency with JEI // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" @@ -170,3 +188,7 @@ idea { isDownloadSources = true } } + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7661e74..562643f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ minecraftVersion=1.20.6 # as they do not follow standard versioning conventions. minecraftVersionRange=[1.20.6,1.21) # The Neo version must agree with the Minecraft version to get a valid artifact -neoVersion=20.6.100-beta +neoVersion=20.6.110-beta # The Neo version range can use any version of Neo as bounds neoVersionRange=[20,) # The loader version range can only use the major version of FML as bounds diff --git a/src/main/java/robaertschi/environmenttech/EnvironmentTech.java b/src/main/java/robaertschi/environmenttech/EnvironmentTech.java index 8a046a7..298b60a 100644 --- a/src/main/java/robaertschi/environmenttech/EnvironmentTech.java +++ b/src/main/java/robaertschi/environmenttech/EnvironmentTech.java @@ -26,6 +26,8 @@ import robaertschi.environmenttech.menu.ETMenus; @Mod(EnvironmentTech.MODID) public class EnvironmentTech { + + public static final String MODID = "environmenttech"; public static final Logger LOGGER = LogUtils.getLogger(); diff --git a/src/test/java/robaertschi/environmenttech/test/TestMain.java b/src/test/java/robaertschi/environmenttech/test/TestMain.java new file mode 100644 index 0000000..502ba81 --- /dev/null +++ b/src/test/java/robaertschi/environmenttech/test/TestMain.java @@ -0,0 +1,17 @@ +package robaertschi.environmenttech.test; + +import net.neoforged.testframework.conf.ClientConfiguration; +import net.neoforged.testframework.conf.FrameworkConfiguration; +import net.neoforged.testframework.impl.MutableTestFramework; +import org.lwjgl.glfw.GLFW; +import robaertschi.environmenttech.EnvironmentTech; + +public class TestMain { + final MutableTestFramework framework = FrameworkConfiguration.builder(EnvironmentTech.id("tests")) + .clientConfiguration(() -> ClientConfiguration.builder() + .toggleOverlayKey(GLFW.GLFW_KEY_J) + .openManagerKey(GLFW.GLFW_KEY_N) + .build()) + + .build().create(); +}