Reference: component tests¶
Validation rules, resource estimations, options bindings, and the config
mappings of workflow operations are testable without any services. A test script lives next to the component it tests and
runs with simkit component test, which builds the component through the
regular pipeline, captures exactly the definition objects the registry
envelope would carry, and executes your named cases against them — what the
tests exercise is what production ships.
Test scripts¶
| Component script | Test script | Top block |
|---|---|---|
<name>.data-type.kts |
<any>.data-type.test.kts |
dataTypeTest { } |
<name>.method.kts |
<any>.method.test.kts |
methodTest { } |
<name>.workflow-type.kts |
<any>.workflow-type.test.kts |
workflowTypeTest { } |
<name>.material.kts |
<any>.material.test.kts |
materialTest { } |
A test script belongs to the single component script of its kind in the
same directory. Several test scripts per component are fine — split them by
concern (mock_mesher_validation.method.test.kts,
mock_mesher_estimation.method.test.kts).
// mock_mesher_validation.method.test.kts
import com.simscale.workflows.framework.measurementunits.units.library.CompoundMetricUnits.MILLIMETER
fun edgeLengthMm(value: Double) = MockMesherConfigDataModel(edgeLength = DimensionalScalar(value, MILLIMETER))
methodTest {
test("edge length below 1 mm is an error and a warning") {
val results = validate { config(edgeLengthMm(0.5)) }
results.shouldHaveError("edge_length", case = "too_small_error")
results.shouldHaveWarning("edge_length", case = "too_small_warning")
}
test("edge length in the preferred range passes") {
validate { config(edgeLengthMm(10.0)) }.shouldBeEmpty()
}
}
Cases are ordinary Kotlin: build configurations, call the evaluation
helpers, assert on the results, loop, extract local functions. The
component's generated classes (MockMesherConfigValueModel,
MockMesherConfigDataModel, dep-generated types) and any utility
sources are on the classpath and
star-imported. Fixture helpers that construct the generated models live in
the test script itself:
fun baseConfig() =
TestConfigMappingConfigDataModel(
presets = listOf(PresetsDataModel(name = "steel", coefficient = 7.85)),
selectedPreset = SelectedPresetDataModel(name = "steel", coefficient = 7.85),
scaleFactor = 1.0,
)
workflowTypeTest {
test("a zero scale factor is rejected") {
validate { config(baseConfig().copy(scaleFactor = 0.0)) }
.shouldHaveExactly(
validationError("scale_factor", "too_small_error", message = "Scale factor must be positive"),
)
}
}
What each scope provides¶
Every scope exposes the captured definition objects, evaluation helpers, and the context builder below.
methodTest { } — captured validationRuleSet and resourceEstimation;
validate { … } → ValidationResultSet; estimateResources { … } →
MethodResourceEstimationDataModel (the same resolve-then-deserialize step
the workflow runner performs); resolveResourceEstimation { … } for the raw
JSON.
dataTypeTest { } — captured dataSchemaValidationRuleSet and
metadataSchemaValidationRuleSet; validateData { … } and
validateMetadata { … }.
workflowTypeTest { } — captured configuration-schema
validationRuleSet, optionsBindingSet, and workflowDefinition;
validate { … }. Assert on binding structure by comparing reference paths:
val config = TestOptionsUiConfigValueModel.fromReference(ConfigValueReference(""))
workflowTypeTest {
test("selected material picks a whole element of the materials list") {
val binding = optionsBindingSet.bindings.single { it.valueReference == config.selectedMaterial.reference() }
binding.options.reference() shouldBe config.materials.reference()
binding.allowEmptySelection shouldBe false
}
}
resolveOperationConfiguration("operation") { … } resolves the
configuration a named operation of the workflow definition would receive —
the same resolution step the workflow runner performs before dispatching the
operation. Supply the workflow configuration via config(…) and assert on
the resolved JSON; an unknown operation name fails with the list of
available operations:
workflowTypeTest {
test("the method operation receives the mapped workflow configuration") {
val configuration =
resolveOperationConfiguration("nativeTest") {
config("""{ "executionControl": { "duration": 20, "terminalState": "FAILURE" } }""")
}
configuration.get("executionControl").get("duration").asInt() shouldBe 20
}
}
Everywhere — resolve(value) { … } evaluates any value-model expression
against a built context, for testing individual sub-expressions (an
estimation formula from a utility source, a message model) in isolation; and
context { … } hands you the built resolution context directly.
Supplying values — the context builder¶
The validate / estimateResources / resolveOperationConfiguration /
resolve helpers take a context block that declares what the referenced
values resolve to:
| Call | Resolves |
|---|---|
config(dataModel) / config(json) |
configValueModel.… references — pass a generated …ConfigDataModel instance or raw JSON |
input(name, metadata = …, sizeInBytes = …) |
input presence, MetadataValueReferences of that input, and dataSizeValueModel(name) |
data(dataModel) / data(json) |
the data content under validation (data-type rules) |
metadata(…) |
the metadata under validation (data-type metadata rules) |
dataSize(bytes) |
the size of the data under validation (data-type rules) |
A materialTest { } needs no context: the scope exposes the serialized properties document and
property("/json/pointer") to assert on it, plus schemaDataTypeReference.
materialTest {
test("the properties document carries the authored properties in the authored units") {
property("/name").asString() shouldBe "Water"
property("/fluidType").asString() shouldBe "LIQUID"
property("/density/value").asDouble() shouldBe 997.33
property("/density/unit").asString() shouldBe "kg/m³"
}
test("the material is bound to the fluid schema") {
schemaDataTypeReference shouldBe "simscale.test:test-fluid-material-schema"
}
}
Undeclared inputs resolve as absent; referencing an undeclared input's metadata or size fails the case with the same kind of error production raises.
test("memory grows with the geometry size") {
val estimation = estimateResources { input("geometry", sizeInBytes = 2L * 1024 * 1024 * 1024) }
estimation.oneProcessorEstimation.memoryInMebibytes shouldBe 2048U
}
Evaluation semantics match a single rule-set run: defaults are not populated into the configuration first, and rule sets of nested data types are not pulled in — supply the full configuration the rules should see.
Assertions¶
Built in — no external test framework. Every helper throws on mismatch; there is no boolean result to accidentally drop.
| Assertion | Checks |
|---|---|
results.shouldHaveError("rule" [, case = "case"]) |
the rule produced an ERROR validation result |
results.shouldHaveWarning("rule" [, case = "case"]) |
… a WARNING validation result |
results.shouldBeEmpty() |
the validation produced no result at all |
results.shouldHaveNoErrors() |
warnings tolerated, errors not |
results.shouldHaveExactly(validationError("rule", "case" [, message = "…"] [, path = "/presets/1"]), validationWarning(…), …) |
every expectation matches one distinct reported case (rule/case/severity, plus message and location when given) and nothing is left over — a per-element rule is expected once per failing element |
actual shouldBe expected |
plain equality |
value.shouldBeCloseTo(expected [, tolerance]) |
numeric closeness, also directly on a resolved JsonNode |
Running¶
simkit component test [<paths>...]
[-j, --parallelism <n>] # components tested in parallel; default: CPU cores
[--junit-xml <file>] # also write a JUnit-style XML report (CI test widgets)
With no input, every test script in the current directory runs; directories are walked recursively. Per component, the build runs once (dependencies resolve from the local repository first, then the registry — nothing is published, no native code is generated) and every test script runs against it. The exit code is non-zero if any case fails.
$ simkit component test e2e/components/methods/mock-mesher
./e2e/components/methods/mock-mesher/mock_mesher.method.kts (5092 ms)
mock_mesher_estimation.method.test.kts
✓ memory grows with the geometry size (19 ms)
✓ memory never drops below the 512 MiB floor (0 ms)
mock_mesher_validation.method.test.kts
✓ edge length below 1 mm is an error and a warning (16 ms)
✓ edge length in the preferred range passes (1 ms)
Done — 7 test(s), 0 failed across 1 component(s), total 5113 ms (wall)
Cross-references¶
- Unified DSL reference — the component scripts under test.
- Validation rules — what the rule sets express.
- Method resource estimation.
- Options bindings.