SITF - Spigot Integration Testing Framework
1.0.2Make your plugin bugs free with Integrations tests
About SITF
This is a tool designed for adding integration tests to spigot plugins. This library is designed to behave simillar to Junit so you will find a lot similarities.
What are Integration tests?
Integration tests are a type of software testing that checks how different components or modules of a system work together. In other words, they test the integration between different parts of the software to ensure that they function correctly and produce the expected results. For example, an integration test for a spigot plugin might test how the player interacts with Commands, Events, Permissions. Integration tests are important for detecting errors or bugs that may arise from the interaction of different components, and for ensuring that the system as a whole works correctly.
Why should I use it?
When code base of your plugin growing rapidly there is harder and harder
to test some funcionaliies manually. To make life easier you can write test code that tests your functionallity automatically.
How to use SITF?
In order to use framework, every class from your plugin which contains a test should extend the abstract class PluginTest. Additionaly by implementing PluginTestsSetup to your main plugin class
tests configuration may be changed
To run tests just put both SpigotTester.jar and your plugin to plugins
folder and run server. Console will display informations about each
test and when all will be done, report will be generated at
server/plugins/SpigotTester/report.json
Maven
Maven
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.jwdeveloper</groupId>
<artifactId>SpigotTester</artifactId>
<version>1.0.2-Release</version>
<scope>provided</scope>
</dependency>Example plugin main
Example plugin main
public final class PluginMain extends JavaPlugin implements PluginTestsSetup {
//Example class that is passed to tests as parameter
private CraftingManager craftingManager;
@Override
public void onEnable() {
// Plugin startup logic
craftingManager = new CraftingManager();
}
//Here you can configure tests and inject parameters
@Override
public void onTestsSetup(TestsBuilder builder) {
builder.addParameter(craftingManager);
}
}Example Test
Example plugin main
public class ExampleTests extends PluginTest {
@Test(name = "crafting permission test")
public void shouldUseCrafting() {
//Arrange
Player player = addPlayer("mike");
CraftingManager craftingManager = getParameter(CraftingManager.class);
PermissionAttachment attachment = player.addAttachment(getPlugin());
attachment.setPermission("crating", true);
//Act
boolean result = craftingManager.canPlayerUseCrating(player);
//Assert
assertThat(result).shouldBeTrue();
assertThatPlayer(player)
.hasName("mike")
.hasPermission("crating");
}
@Test(name = "teleport only player with op")
public void shouldBeTeleported() {
//Arrange
Player playerJoe = addPlayer("joe");
Player playerMike = addPlayer("mike");
//Act
invokeCommand(playerJoe, "teleport " + playerJoe.getName() + " 1 3 3");
playerMike.setOp(true);
invokeCommand(playerMike, "teleport " + playerMike.getName() + " 1 2 3");
//Assert
assertThatEvent(PlayerTeleportEvent.class)
.wasInvoked(Times.once()) //since only one player has OP event will be triggered once
.validate();
assertThatCommand("teleport")
.wasInvoked(Times.once())
.byPlayer(playerJoe)
.validate();
assertThatCommand("teleport")
.wasInvoked(Times.once())
.byPlayer(playerMike)
.validate();
}
}Generated tests report
server/plugins/SpigotTester/report.json
Generated tests report
{
"isPassed": true,
"reportId": "a7e47b6d-4165-4692-a286-b07404d37401",
"createdAt": "2023-02-17 15:11:35.4724659+01",
"serverVersion": "3638-Spigot-d90018e-7dcb59b (MC: 1.19.3)",
"spigotVersion": "1.19.3-R0.1-SNAPSHOT",
"spigotTesterVersion": "1.0.0-Release",
"plugins": [
{
"isPassed": true,
"pluginVersion": "1.0.0",
"pluginName": "ExamplePluginToTest",
"classResults": [
{
"className": "ExampleTests",
"classPackage": "io.github.jwdeveloper.spigot.exampleplugintotest",
"isIgnored": false,
"isPassed": true,
"testMethods": [
{
"name": "teleport only player with op",
"isPassed": true,
"executionTime": 26.0652,
"isIgnored": false,
"errorMessage": "",
"stackTrace": ""
},
{
"name": "crafting permission test",
"isPassed": true,
"executionTime": 18.7894,
"isIgnored": false,
"errorMessage": "",
"stackTrace": ""
}
]
}
]
}
]
}Similar projects
Plugin →Let Me Despawn
Improves performance by tweaking mob despawn rules. Say bye to pesky unintentional persistent mobs.
25MSueta
JourneyMap
Real-time map used for mapping in-game or your browser as you explore.
14.7MSueta
Emotecraft
Create your own emotes in Minecraft.
7.5MSueta
Simple Tpa
A simple tpa plugin which sends requests
5.4MSueta
Common Network
Forge and Fabric Unified Networking Solution
3.9MSueta
Set Home
A lightweight plugin for players to set their homes.
3.8MSueta