Play tests
Write a scenario file, and bots play your game on your developer server while every step is checked.
What a play test is
A play test is a plain text file of steps: bots join your game, walk, look, click, use items, chat and run commands, and after each step you can say what must have happened: a chat line, a position, an item, a world, alive or dead. strawberry-kit test --play puts your script on your developer server with the scenario built in, the bots play it, and the result of every step comes back to your terminal with the server's console.
The bots are simulated players: players on the server with no connection. They exist only on a developer server, at most 16 at once.
Add the runner to your script
The runner is part of the Creator Kit. Turn on its feature playtest:
creator-kit = { version = "...", registry = "strawberry", features = ["sdk", "playtest"] }The Creator Kit release is 0.1.1, made for SDK 0.2.4: use the two dependency lines from Get the SDK.
Then start it at the end of on_load:
fn on_load(&self, context: Context) -> Result<()> {
// ... your handlers and commands ...
creator_kit::sdk::playtest::start(&context, creator_kit::playtest_scenario!())?;
Ok(())
}playtest_scenario!() is the scenario of a test --play build, and nothing in any other build: an ordinary test, build or upload carries no scenario, and start then does nothing.
Run it
strawberry-kit test --play tests/party.play --template lobby- The scenario is read first. A wrong line stops here, with its number and what is wrong, before anything is built.
- Your script is built with the scenario and uploaded to your developer server.
- With
--template, the test session starts from that stored world (or starts again when one runs), so every run begins in the same fresh world. The tool remembers the template: without--template, it uses the last one you named. - Your script is reloaded. Two seconds later the bots join and the steps run.
- The tool reads the console until the result is there, then shows the passed steps or the step that failed, with its line, and the server's last lines.
The command ends with an error when a step failed or when no result came in time, so a script or CI can use it.
The scenario file must be inside your project. With an AI app, the MCP tool test takes the same file as play.
The scenario format
One step per line. Blank lines are skipped; # starts a comment, at the start of a line or after a space.
# tests/party.play
name Party joins and the leader starts
timeout 5s
bot Ann
bot Ben at 2.5 64 0.5 adventure
Ann chat /party invite Ben
Ben chat /party accept
Ben chat ready
expect chat from Ben ready
Ann walk 10.5 64 3.5
Ann expect at 10.5 64 3.5
Ann click 10 64 4
Ann expect world level-1
Ann expect item minecraft:compass
wait 2s
Ben leaveSettings
Line | What it does |
|---|---|
| The scenario's name, shown when it starts. |
| The world the bots join. Without it: the test session's world when one runs, else the server's first world. |
| How long each later |
A time is in ticks (40, 40t) or seconds (2s, 1.5s), at most 10 minutes.
Bots
Line | What it does |
|---|---|
| A bot joins at the world's spawn, in survival. |
| It joins at that position, in |
A bot's name is 3 to 16 letters, digits or _, and is never one of the step words (bot, wait, expect, name, world, timeout, run). A bot is named with bot before its first step. A scenario has at most 16 bots.
What a bot does
Line | What it does |
|---|---|
| Says a chat line; a text starting with |
| Walks there in a straight line and waits until it arrives (within a block). |
| Looks at that point. |
| Jumps. |
| Uses the item in hotbar slot 0 to 8, as a right click in the air. |
| Uses it on a block, optionally on one face. |
| Right-clicks a block: a button, a lever, a chest, a sign. |
| Hits that player (a bot or anyone online). |
| Right-clicks that player. |
| Presses respawn after a death. |
| Disconnects. |
| Nothing happens for that long. |
A face is up, down, north, south, west or east. Every action is checked by the server like a player's input: reach, cooldowns, movement and permissions.
Walking is in a straight line, without path finding. For path finding, building, flying, gliding or swimming, drive simulated players in Rust.
What to expect
Line | It holds when |
|---|---|
| A chat line containing the text was sent, by anyone. |
| The same, from that player. |
| The bot was sent a message containing the text. |
| The bot is within that distance of the point (1 block by default). |
| The bot holds at least that many of the item (1 by default) in any slot. |
| The bot holds none of it. |
| The bot is in that world. |
| The bot is alive. |
| The bot is dead. |
An expect is checked every tick until it holds or its timeout runs out. expect chat looks at the chat lines sent since the last expect chat that held, so a line said just before the expect is not missed, and one line is not counted twice.
expect chat sees only the lines that players type. To check what the server or your script said to a bot (a command's answer, a message, a title, a subtitle or the action bar), use expect message: Ann expect message invited Ben. Name a kind to narrow it (system, chat, title, subtitle or action-bar), for example Ann expect message title Round 1.
An item id without a namespace gets minecraft:.
When a step fails
The run stops at the first step that fails, and every bot of the run leaves. The tool shows the step, its line in the file and what was there instead: where the bot stood, how many items it held, which world it was in, or the server's own words when it refused an action (no developer server, 16 simulated players already, a name that is taken).
The bots also leave when the run passes and when your script is unloaded, so the next run starts clean.
Game tests on a developer server
A game test is a Rust function that runs inside a structure, as in Bedrock's GameTest. Game tests run only on developer servers.
- Build your script with the
gametestfeature of the SDK. - Register each test and set its limits on the returned builder:
max_ticks(20 by default),setup_ticks,batch,max_attempts,structure_nameandtag. - Put the structure the test works in as
mytests/structure/placing.nbtin your script's data pack, or name another withstructure_name. - On a developer server, an operator runs the test with a command.
use strawberry_plugin_api::gametest;
let builder = gametest::register("mytests", "placing", |test| {
let spot = gametest::BlockPos { x: 1, y: 1, z: 1 };
test.set_block_type("minecraft:stone", spot)?;
test.succeed_when(move |test| test.assert_block_present("minecraft:stone", spot, Some(true)))?;
Ok(())
})?;
builder.max_ticks(40)?;Command | What it does |
|---|---|
| Runs one test. |
| Runs every test tagged |
| Stops the tests that run. |
| Removes the tests from the world. |
The test is built next to the operator and its function runs. It passes when it calls succeed (or a succeed_when check stops failing) and fails on fail, a failed assertion, or when max_ticks run out. Each test reports one line in chat, in the language of whoever started the run, and one in the console, then a summary line follows.
Bedrock's Test functions work with Java behaviour, for example assert_block_present, assert_block_state(pos, |state| ...), assert_entity_state(...), assert_redstone_power, assert_container_contains, assert_item_entity_count_is, assert_can_reach_location, spawn, spawn_item, spawn_without_behaviors with walk_to, pull_lever, press_button, pulse_redstone, set_fluid_container, destroy_block, kill_all_entities, spawn_simulated_player, succeed_when_block_present and sequences. The checks that need entity components answer an error.
A test registered with gametest::register_async can wait inside its body: test.idle(ticks).await goes on that many ticks later, and test.until(condition).await waits until the condition holds. A failed assertion inside the condition only means that it does not hold on that tick. The body resumes in short steps, so your script stays responsive while it waits. In a test registered with register, use after, succeed_when or a sequence instead.
What a play test does not test
The bots are Java players on the server. A play test checks your game's logic, not what a Bedrock client or a vanilla client is shown: a title, a sound, a particle, a resource pack. Check those yourself with a real client in a test session.