Skip to content

Commit

Permalink
add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockedPlot7560 committed Sep 21, 2023
1 parent e1a813c commit bb93326
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## PmUnitTest - Unit Testing Framework for PocketMine

This plugin has been created with the sole aim of making unit, integration and functional tests possible during the pocketmine runtime.

It can be used to correctly test the expected result of a command executed by a fake player, interaction with events and multi-threading support.

Tests are run asynchronously using promises to enable support with different systems in place. The libraries used for the promises are : [ReactPHP/promise](https://github.com/reactphp/promise)

> [!WARNING]
> This plugin should not be used in production, as it will shutdown the server as soon as testing is complete.
## Utilisation

Tests are retrieved from the folder: `plugin_data/PmUnitTest/tests/` and are executed when the server start.

All test classes must inherit from `ShockedPlot7560\UnitTest\frameworkTestCase`.
All test methods must be prefixed with `test` and must not have any parameters, it must return a `PromiseInterface<null>`.
If the code is executed synchronously and does not have to wait for a result, use `resolve(null)`.
Use `Deferred` instead for asynchronous code and `$deferred->resolve(null)` to resolve the promise.

Each test class can execute code when the server is `onLoad`, `onEnable` or `onDisable`. Simply use the corresponding classes.

`setUp` and `tearDown` are called when each class test is run, respectively before and after the test, whatever the result.

### TestPlayer utilisation

To retrieve one player during a test, call ``getPlayer()``.
To test player commands or behavior, create your promise/listener before executing the action. Return the promise in the test method.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: UnitTest
name: PmUnitTest
version: 0.0.1
main: ShockedPlot7560\UnitTest\UnitTest
api: 5.0.0
Expand Down

0 comments on commit bb93326

Please sign in to comment.