Back to Repositories

Testing Generic Mod Management Integration in Mindustry

This test suite implements core functionality for handling and validating Mindustry game mods. It provides essential utilities for downloading, installing, and verifying mod installations in a test environment.

Test Coverage Overview

The test suite covers critical mod management functionality including:
  • Mod download and installation validation
  • File system operations for mod storage
  • Mod loading and initialization verification
  • Error handling for download failures and IO operations
Key integration points include HTTP downloads, file system operations, and mod registry interaction.

Implementation Analysis

The testing approach utilizes JUnit Jupiter for structured test execution and assertion handling. The implementation employs helper methods for common operations like mod retrieval and validation, following a modular pattern. Key technical aspects include HTTP client usage, stream handling, and filesystem operations with error propagation.

Framework-specific features leverage JUnit’s assertion framework and test lifecycle management.

Technical Details

  • JUnit Jupiter test framework
  • Arc utility library for HTTP and IO operations
  • Custom test data folder management
  • Automated mod cleanup and installation
  • Timeout handling for network operations
  • Stream-based file operations

Best Practices Demonstrated

The test suite exemplifies several testing best practices including proper resource cleanup, explicit error handling, and clear assertion messages. Notable practices include:
  • Isolated test environments
  • Defensive programming with null checks
  • Clear helper method organization
  • Descriptive assertion messages
  • Timeout handling for external operations

anuken/mindustry

tests/src/test/java/GenericModTest.java

            
import arc.util.*;
import arc.util.io.*;
import mindustry.*;
import org.junit.jupiter.api.*;

import java.io.*;

import static org.junit.jupiter.api.Assertions.*;

public class GenericModTest{

    /** grabs a mod and puts it in the mod folder */
    static void grabMod(String url){
        //clear older mods
        ApplicationTests.testDataFolder.deleteDirectory();
        Http.get(url).error(Assertions::fail).timeout(20000).block(httpResponse -> {
            try{
                ApplicationTests.testDataFolder.child("mods").child("test_mod." + (url.endsWith("jar") ? "jar" : "zip")).writeBytes(Streams.copyBytes(httpResponse.getResultAsStream()));
            }catch(IOException e){
                Assertions.fail(e);
            }
        });

        ApplicationTests.launchApplication(false);
    }

    static void checkExistence(String modName){
        assertNotEquals(Vars.mods, null);
        assertNotEquals(Vars.mods.list().size, 0, "At least one mod must be loaded.");
        assertEquals(modName, Vars.mods.list().first().name, modName + " must be loaded.");
    }
}