Overview
Skript includes a comprehensive testing framework that supports both script-based tests and JUnit tests. This allows you to verify that your custom syntax elements work correctly.JUnit Testing
Skript provides base classes for writing JUnit tests that can interact with Bukkit and Skript.SkriptJUnitTest Base Class
/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java:30-116
Test World Setup
The test world is automatically configured with appropriate game rules:/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java:15-28
Cleanup After Tests
/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java:56-60
Setting Test Delays
If your test needs time to complete:/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java:38-52
Writing a JUnit Test
Basic Test Structure
Tests Requiring Delays
Test Execution Flow
Skript’s test runner executes tests with this flow:/src/main/java/ch/njol/skript/Skript.java:994-1039
Script-Based Testing
Skript also supports writing tests directly in Skript syntax.Test Case Event
/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java:14-52
Example Test Script
Test Mode Configuration
Tests run in specific modes controlled by system properties:Running Tests
Skript runs all tests during the test phase:/src/main/java/ch/njol/skript/Skript.java:880-902
Best Practices
Clean up after tests
Clean up after tests
Always implement the
cleanup() method to remove entities and reset blocks.Use appropriate delays
Use appropriate delays
Set
shutdownDelay when your test needs time for async operations to complete.Test edge cases
Test edge cases
Write tests for null values, empty inputs, and boundary conditions.
Keep tests isolated
Keep tests isolated
Each test should be independent and not rely on other tests’ state.
Example: Complete Test Suite
Next Steps
Syntax Registration
Learn more about registering custom syntax
Addon Development
Back to addon development overview
