Guide MockBukkit: A Testing Framework for Minecraft Plugins

thelooter

New member
Nov 9, 2024
1
0
1
Germany
thelooter.de
logo.png
Introduction

Hey people of Paper! We just released version 4.0 of MockBukkit, a testing framework that makes unit testing Paper/Spigot plugins straightforward and efficient. If you've been thinking about adding tests to your plugins, now might be a great time to start!

What is MockBukkit?

MockBukkit provides mock implementations of the Bukkit API, allowing you to write unit tests for your plugins without running a server. This means you can verify your plugin's behavior quickly and reliably, just like you would with any other Java application.

Features

  • Write tests using standard tools like JUnit and Hamcrest
  • Test events, commands, and player interactions without a running server
  • Run your entire test suite in seconds
  • Simulate complex plugin scenarios easily
  • Clear, comprehensive documentation at docs.mockbukkit.org

Example
Java:
@Test
void playerJoinsServer() {
    // Create a test plugin
    TestPlugin plugin = MockBukkit.load(TestPlugin.class);
 
    // Simulate a player joining
    PlayerMock player = server.addPlayer();
 
    // Verify your plugin's behavior
    assertThat(player.getGameMode(), is(GameMode.SURVIVAL));
    assertThat(player.getInventory(), hasItem(Material.COMPASS));
}


Getting Started

Check out our website at mockbukkit.org and our docs.mockbukkit.org to get started. If you need help, feel free to join our Discord community!

Lastly

We hope you enjoy using MockBukkit 4.0 and we look forward to your feedback!