PluginTestHarness

Runs a built plugin jar on the real SDK runtime and a fake car, so a plugin's host tests need no setup code.

start copies the jar into a temporary "unit" under the test's temp directory, installs what the unit would hold after the user installed the package (grants, icons), starts SdkRuntime on FakePlatform and waits until the plugin is ENABLED. Drive the plugin through ui and car, move time with advance, and assert on what the UI shows and what the plugin stored.



void startsEnabled(@TempDir File tmp) {
    try (PluginTestHarness h = PluginTestHarness.start(tmp)) {
        h.await(() -> !h.ui().render(h.pageKey("main")).isEmpty(), "the page");
    }
}

Where the files come from: the plugin jar is -Dmibsdk.pluginJar (or jar); the icon PNGs are <name>.png in -Dmibsdk.pluginIcons (or icons), by default src/main/icons of the project under test. The build sets both properties for a plugin's tests.

What the "unit" is given, so a test sees the same thing every time:

  • sdk.properties is plugin.start.delay.ms=0 (no start delay), heap.low.bytes=0 (no heap guard), ui.publish.min.ms=0 (no UI throttle) and log.file=<tmp>/mibsdk.log.
  • grants.properties grants the permissions given to grants, by default every permission the plugin's plugin.json declares.
  • The unit has the features given to features, by default every Features constant.
  • Icons are installed as mibpkg does: each icon in plugin.json is copied to icons/<id>/<sha16>.png, where sha16 is the first 16 lowercase hex characters of the PNG's SHA-256, with an index.properties line <name>=<sha16>,<width>,<height>. iconSha gives the sha16 for an assertion such as "[png:" + h.iconSha("cup") + "] Coffee".
  • The Scheduler's clock is the real uptime plus advance.
  • The plugin's storage starts with the values given to storedValues, by default empty.

After restart the harness has a new runtime, UI and car: call ui and car again. Waits last 5 seconds. A harness is for one plugin on one thread; close stops the runtime.

Types

Link copied to clipboard
class Builder

Functions

Link copied to clipboard
open fun advance(ms: Long)
Moves the plugin's Scheduler clock forward by ms; due tasks run on the plugin's own thread soon after.
Link copied to clipboard
open fun await(condition: BooleanSupplier, what: String)
Waits up to 5 seconds for condition; fails with what, the plugin's pages and the runtime log.
Link copied to clipboard
A harness for the jar in -Dmibsdk.pluginJar and the icons in -Dmibsdk.pluginIcons.
Link copied to clipboard
open fun car(): FakePlatform
The fake car: ignition, parking and the ECU.
Link copied to clipboard
open fun close()
Stops the runtime.
Link copied to clipboard
open fun iconSha(name: String): String
The first 16 hex characters of the SHA-256 of icon name: the key a [png:<key>] tag shows.
Link copied to clipboard
open fun log(): String
The runtime's log, oldest line first.
Link copied to clipboard
open fun openPage(pageId: String)
Opens the plugin's page pageId as a user does: through the link on the plugin's Plugins-menu page.
Link copied to clipboard
open fun pageKey(pageId: String): String
The key of one of the plugin's pages for FakeUi: "<id>/<pageId>".
Link copied to clipboard
open fun pluginId(): String
The plugin's id from its plugin.json.
Link copied to clipboard
open fun restart()
Stops the runtime and starts a new one on the same temp directory (storage kept); waits until ENABLED.
Link copied to clipboard
open fun start(tmp: File): PluginTestHarness
builder(tmp).start().
Link copied to clipboard
open fun state(): String
The plugin's lifecycle state by PluginState name, e.g.
Link copied to clipboard
Stops the runtime (which flushes the plugin's storage) and reads data/<id>.properties; empty if none.
Link copied to clipboard
open fun ui(): FakeUi
What the user sees and presses: Car rows, the status line, pages, dialogs and toasts.