Skip to content

These docs describe Bloom 0.1.0, a pre-release. APIs may change before 1.0, and Bloom is not on Maven Central yet (see Installation).

Testing

Unit-test plugin logic without a server, test against MockBukkit, and how Bloom itself is verified.

Unit tests without a server

Write game logic against BloomScheduler and Clock instead of Bukkit's scheduler and System.currentTimeMillis(), then drive time yourself with bloom-testing:

JavaView source
/** Code under test depends on BloomScheduler, not on Bukkit, so it can be tested without a server. */
final class Countdown {
    private final BloomScheduler scheduler;
    private int remaining;

    Countdown(BloomScheduler scheduler) {
        this.scheduler = scheduler;
    }

    void start(int seconds) {
        remaining = seconds;
        scheduler.syncRepeating(
                task -> {
                    if (--remaining <= 0) {
                        task.cancel();
                    }
                },
                20,
                20);
    }

    boolean finished() {
        return remaining <= 0;
    }
}

class CountdownTest {
    @Test
    void finishesAfterThreeSeconds() {
        ManualScheduler scheduler = ManualScheduler.create();
        Countdown countdown = new Countdown(scheduler);
        countdown.start(3);

        scheduler.tick(59);
        assertTrue(!countdown.finished());
        scheduler.tick();
        assertTrue(countdown.finished());
        assertEquals(0, scheduler.activeTaskCount());
    }
}

ManualScheduler runs nothing until you call tick(). "Async" tasks also run during ticks, on the test thread, so tests need no sleeps. It shares the real scheduler's cancellation and error handling. TestClock does the same for Cooldowns and ExpiringCache.

build.gradle.kts
dependencies {
    testImplementation("io.github.crownalonedev.bloom:bloom-testing:0.1.0")
}

MockBukkit

For modern Paper behaviour you can test with MockBukkit: Bloom detects it and loads the modern adapter. MockBukkit only exists for modern Paper; there is no maintained mock for 1.8.

How Bloom is tested

  • Unit tests for every module; the server-independent modules also run on a real Java 8 runtime.
  • MockBukkit integration tests that load the real modern adapter, plus every example plugin's shaded and relocated jar.
  • Compile checks of the modern adapter against Paper 1.21.1, 1.21.11 and 26.3.
  • SQLite tests on the old sqlite-jdbc 3.7.2 driver, and MySQL 8.4 / MariaDB 11 tests in CI.
  • bloom-doctor linkage checks of every example plugin against spigot-api 1.8.8 and paper-api 1.21.11 and 26.3.
  • A real-server harness, scripts/realserver/run.sh (run.bat on Windows), which downloads an official Paper or PaperSpigot build, checks its SHA-256, starts it with a self-test plugin and reports the result. Running a server means accepting the Minecraft EULA: run.bat asks you to type YES, and run.sh only runs when you set BLOOM_ACCEPT_MINECRAFT_EULA=true yourself. It has passed on PaperSpigot 1.7.10 and 1.8.8 and Paper 1.21.11 and 26.3.