| title | parent | grand_parent | nav_order |
|---|---|---|---|
Test Annotations |
Unit Testing |
Advanced Topics |
3 |
Marks a function as a unit test. The function runs as a test case when tests are executed.
@test
fun test_addNumbers() {
$sum: 1 + 2;
@.Assert.equal(3, $sum);
}When no parameters are given, the function name is used as the test name.
@test("Addition of positive numbers")
fun test_addNumbers() {
@.Assert.equal(3, 1 + 2);
}@test("Check total", "math")
fun test_total() {
@.Assert.equal(10, 5 + 5);
}@test({ name: "Grouped test", group: "math" })
fun test_grouped() {
$value: 30;
@.Assert.equal(30, $value);
}Use the object form when you need both a custom name and group.
| Form | Example | Result |
|---|---|---|
| No params | @test |
Test name = function name |
| String | @test("My test") |
Test name = "My test" |
| Two strings | @test("Name", "group") |
Custom name and group |
| Object | @test({ name: "x", group: "y" }) |
Custom name and group |
Marks a function to run before each test in the same file. Use it for shared initialization.
- At most one
@setupfunction per file - Runs before every
@testfunction in that file - Does not run as a test itself
@setup
fun setup() {
$sharedState: { count: 0 };
// This runs before each test
}
@test
fun test_first() {
// setup() already ran
@.Assert.equal(1, 1);
}
@test
fun test_second() {
// setup() runs again before this test
@.Assert.equal(2, 2);
}A typical test file:
// Optional: imports
import Helper from "../helper.isl";
@setup
fun setup() {
// Runs before each test
}
@test
fun test_basic() {
// Test code
}
@test("Custom name")
fun test_withName() {
// Test code
}
@test({ name: "Edge case", group: "validation" })
fun test_edgeCase() {
// Test code
}