Test environment definition

A test environment is a way to group up GameTests and give them the right preconditions to run.

Definition

Test environments can be defined in data packs, as part of the directory structure below.

JSON Format

Test environments are defined using the following format:

  • [NBT Compound / JSON Object] The root object.
    • [String] type: Indicates how to set up the test. See below.
    • Other additional fields depend on the value of [String] type, described below.

Environment types

all_of

Applies multiple environments

  • [NBT Compound / JSON Object] The root object.
    • [String] type: all_of
    • [NBT List / JSON Array] definitions
      • [String][NBT Compound / JSON Object]: One test environment (an [String] ID, or a new [NBT Compound / JSON Object] test environment definition) — Another test environment.

function

Uses functions to set up and tear down the test.

  • [NBT Compound / JSON Object] The root object.
    • [String] type: function
    • [String] setup: (optional) One function (an [String] ID) — the function to use for setup.
    • [String] teardown: (optional) One function (an [String] ID) — the function to use for teardown.

game_rules

Applies game rules during the test, and resets them after tests have completed.

  • [NBT Compound / JSON Object] The root object.
    • [String] type: game_rules
    • [NBT List / JSON Array] bool_rules: A list of boolean game rules to set and the value to set.
      • [NBT Compound / JSON Object]: A map of boolean game rule.
        • [String] rule: Name of the game rule.
        • [Boolean] value: Value to set.
    • [NBT List / JSON Array] int_rules: A list of integer game rules to set and the value to set.
      • [NBT Compound / JSON Object]: A map of integer game rule.
        • [String] rule: Name of the game rule.
        • [Int] value: Value to set.

weather

Applies specific weather during the test, and resets it after tests have completed.

  • [NBT Compound / JSON Object] The root object.
    • [String] type: weather
    • [String] weather: The weather to set. Must be one of clear, rain and thunder.

time_of_day

This section describes content that will likely be removed in a future update of Java Edition.
 
This content has been removed in development versions for Java Edition 26.1, but the full update removing it has not been released yet.

Changes the time to the specified value, and resets it after tests have completed.

  • [NBT Compound / JSON Object] The root object.
    • [String] type: time_of_day
    • [Int] time: The time of day to set in number of ticks, as a non-negative integer.

clock_time

This section describes content that is currently in development for Java Edition.
 
This content has appeared in development versions for Java Edition 26.1, but the full update adding it has not been released yet.

Changes the time of a specified world clock to the specified value, and resets it after tests have completed.

  • [NBT Compound / JSON Object] The root object.
    • [String] type: world_clock
    • [String] clock: One world clock (an [String] ID) of which to set the time.
    • [Int] time: The time in ticks to set the clock to.

History

Java Edition
1.21.525w03aAdded test environment definition to data packs.
25w04aRenamed raining environment type to weather
Upcoming Java Edition
26.1snap3Renamed time_of_day environment type to clock_time and added [String] clock field.

Navigation