Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Testing

Alan Gomes edited this page May 21, 2019 · 1 revision

This starter is designed to allow writing tests as easy as possible. Since Bukkit's own design is not the best for testing, it's still necessary to make some mocks in the server classes.

First, you need to implement some mocks for the Player, Server, FileConfiguration and BukkitScheduler classes. Don't worry, the basic implementation is already done and should fit for most test cases, you just need to copy this class into your project test files.

After setting up the mocks, you can start writing tests using this structure:

@RunWith(SpringRunner.class)
@ContextConfiguration(
        classes = MyApplication.class,
        initializers = SpringSpigotTestInitializer.class
)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class SomeServiceTest {
    
    @Autowired
    private SomeService someService;
    
    // your tests here
    
}

Like any traditional spring tests, you can inject and mock beans, as well as use any starters for testing.

Clone this wiki locally