Lesson 12 of 13 · 16m
Testing Plugins: MockBukkit and a Real Server
Keep Bukkit types at the edges, MockBukkit for lifecycle tests, and run-paper for a real headless Paper instance.
Bukkit.getServer() is a static call into a running server, which makes a plugin the least unit-testable codebase you will own. The honest answer is a split: unit-test the parts that are plain Java, mock the Bukkit surface for lifecycle logic, and run integration checks against an actual Paper server for everything else.
The plain-Java majority
Most bugs live in your own classes — the claim-region math, the config migration, the message formatter. Those take a normal JUnit test; no server needed. The design rule that makes it possible is boring: keep Bukkit types at the edges. A ClaimService that takes coordinates and returns a Set is testable. One that takes Player and calls player.getWorld() inside the math is not. Pass primitives in, pass results out.
MockBukkit for the lifecycle
MockBukkit (io.github.seeseemelk:MockBukkit-v1.21) emulates enough of a Paper server for real tests:
class SudoToolsTest {
private ServerMock server;
private SudoToolsPlugin plugin;
@BeforeEach
void setUp() {
server = MockBukkit.mock();
plugin = MockBukkit.load(SudoToolsPlugin.class);
}
@AfterEach
void tearDown() { MockBukkit.unmock(); }
@Test
void joinListenerWelcomes() {
PlayerMock p = server.addPlayer();
server.getPluginManager().callEvent(
new PlayerJoinEvent(p, Component.text("joined")));
p.assertSaid("Welcome");
}
}MockBukkit.mock() builds a ServerMock; MockBukkit.load(...) runs your plugin's real onEnable against it — including saveDefaultConfig, listener registration, and command wiring — and PlayerMock simulates joins, inventory interactions, block breaks (p.simulateBlockBreak(...)), and command sends, with assertions like assertSaid and nextMessage(). It covers listeners, commands, and lifecycle ordering — the class of bugs a config typo hides until production.
Know the limits before you rely on it: no real world ticking, no client, partial coverage of newer API surfaces. MockBukkit proves your code did the right thing given an event. It does not prove the server sends that event the way you assumed.
What to actually test
Order matters when time is short: (1) onEnable wiring — does the plugin enable cleanly with a fresh data folder; (2) command permission gates — op vs non-op vs console; (3) listener behavior on the events that cost money — a cancelled BlockBreakEvent in the wrong place is a grief vector, not a typo. Everything below that line is the same JUnit you write anywhere.
Integration against real Paper
The end-to-end check is a real server. xyz.jpenilla.run-paper (./gradlew runServer) boots Paper with your jar installed; in CI the same thing runs headless — download the Paper build through the api.papermc.io v2 endpoint, boot, wait for Done in latest.log, run a scripted scenario, grep the log for exceptions. That catches what mocks cannot: PluginClassLoader resolution, plugin.yml mistakes, API methods missing on your oldest supported version.
A useful smoke set on a headless server: plugin shows green in /plugins, /yourcommand replies, an op-only subcommand denies a fresh player, and the log holds zero stack traces through two restarts. Script it once — a five-line bash script is enough — and it runs on every commit for the rest of the plugin's life.
Field notes
onEnableandonDisableare the highest-value test targets; most production failures are lifecycle failures. MockBukkit'sload()exercising them is worth the dependency alone.server.execute("sudo", sender, "reload")drives your commands end-to-end inside the mock — test the parser, not just the executor method.- Test against the oldest Minecraft version you claim to support.
NoSuchMethodErroron an old server is a download-page lie. - Keep tests off live data: temp
getDataFolder()paths, a throwaway SQLite file, never your dev server'sworld/.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Bukkit, Spigot, Paper, Folia: What You're Actually Running
There is a fifteen-year fork tree underneath every Minecraft server, and most admins copy a jar without knowing what's in it. Here's the whole chain, with the code — including the config key most DAB guides get wrong.
A Minecraft Mod Is a Program. In 2026, Attackers Started Acting Like It.
A Minecraft mod is a Java program that runs with your account's full permissions, and nothing in the game checks what it does.
Minecraft 26.3 Turned the Whitelist On. Your Server Probably Didn't Notice.
A fresh Minecraft 26.3 server now ships with white-list=true, so new servers are closed to strangers from the first start. Existing servers that upgraded kept their old value, which for most of them means still open.
Your Minecraft Server Isn't Slow, It's Misconfigured
Can't keep up! is not a hardware message. It's the server telling you a tick took longer than 50ms, and almost every cause is a default nobody changed. Here's what actually moves MSPT, with the flags that are now wrong and the setting that isn't where every guide says it is.