跳到正文

Observer

作者:GMDU

Unit testing datapack for unit testing datapacks

收藏

截图

介绍

中文介绍正在准备中,下面暂时显示原文。

Observer

Unit testing for Datapacks.

Overview

Currently this project is in early alpha. It is based on the unit testing functionality from moxlib, although has been moved in to its own project for further love and attention.

The current syntax of Observer is inspired by RSpec.

If you have multiple tests you would like to run at once, place them in functions,
then add those functions to the tag #observer:api/test. Each of the functions must also
call observer:api/perform themselves.

When you run observer:api/start, it will run all the tests at once, and number them.

API

Perform

Checks that the receives tag matches the expects tag.

A test should first run the function needing to be tested, and set the output
of the function into the receives tag.

Note The test suite does not follow the same syntax as the other functions.

Function: observer:api/perform
Storage: observer:test/it
Expects:

  • describes — the name of the test, as a string
  • expects — the expected NBT data
  • receives — the data received from the function output

Returns: The function will tellraw to the executing player the results.

Example:

/function example:return_true
/data modify storage observer:test/it describes set value "always returns true"
/data modify storage observer:test/it expects set value true
/data modify storage observer:test/it receives set from storage example:return_true output
/function observer:api/perform
---
*1 Passed: "always returns true"*

Start

Runs the tests as listed in #observer:api/test.

Function: observer:api/start
Expects: No value expected
Returns: No value returned

Example:

/function observer:api/start
---
*1 Passed: "always returns true"*
*2 Passed: "always returns false"*
*3 Failed: "should returns true"*
  - Expected: true
  - Received: false

常见问题

Observer 支持哪些 Minecraft 版本?

Observer 支持 Minecraft Java 版 1.20.5–1.21.11,共 14 个版本。下载时注意选择和你游戏版本一致的文件。

Observer 怎么安装?

新建世界时在「数据包」里把下载的 .zip 拖进去;已有的存档,把文件放进存档目录下的 datapacks 文件夹,进游戏输入 /reload 即可生效。服务器同样放在世界目录的 datapacks 里。

评论

登录后评论和评分

GMDU 的其他作品

查看全部 →