Plugins
TestFlyPlugin is the main extension point for adding behaviour that runs alongside the framework. Plugins are discovered automatically via Java SPI — no registration code needed in your tests.
Create a plugin
import io.testfly.config.TestFlyConfig;
import io.testfly.extension.TestFlyPlugin;
public class SlackNotificationPlugin implements TestFlyPlugin {
@Override
public String getName() {
return "slack-notification";
}
@Override
public String minFrameworkVersion() {
return "0.7.0"; // framework checks this before loading
}
@Override
public void onLoad(TestFlyConfig config) {
// called once after config is loaded — read settings, open connections
String baseUrl = config.getExecution().getBaseUrl();
System.out.println("SlackPlugin initialised for " + baseUrl);
}
@Override
public void onUnload() {
// called once after all reports are generated — flush, close, clean up
}
}
Register via Java SPI (auto-discovery)
Create the SPI registration file in your project:
src/main/resources/META-INF/services/io.testfly.extension.TestFlyPlugin
Contents — one fully-qualified class name per line:
com.example.plugins.SlackNotificationPlugin
TestFly discovers and loads this plugin automatically when your JAR is on the classpath. No listener registration, no config entries.
Register programmatically
For plugins that need to be registered before framework boot:
import io.testfly.extension.PluginRegistry;
import io.testfly.config.ConfigurationLoader;
PluginRegistry.register(new SlackNotificationPlugin(), ConfigurationLoader.load());
Version compatibility
Declare the minimum framework version your plugin requires:
@Override
public String minFrameworkVersion() {
return "0.7.0";
}
If the running framework is older, the plugin is skipped with a warning — it will not fail the build. You can also assert from inside onLoad:
import io.testfly.extension.FrameworkVersion;
@Override
public void onLoad(TestFlyConfig config) {
FrameworkVersion.requireAtLeast("0.7.0"); // throws IncompatiblePluginException if too old
}
Check the current version at runtime:
String version = FrameworkVersion.get(); // e.g. "0.7.0"
Plugin lifecycle
Suite starts
→ PluginRegistry.loadAll() // SPI discovery + onLoad() called
→ [all tests run]
→ Reports generated
→ PluginRegistry.unloadAll() // onUnload() called on every plugin
Suite ends
onLoad failures are logged but do not abort the suite. onUnload failures are also isolated.
What plugins are good for
| Use case | Approach |
|---|---|
| Suite-level setup/teardown | onLoad / onUnload |
| Reading framework config | onLoad(TestFlyConfig config) |
| Initialising external clients | onLoad |
| Flushing metrics / closing connections | onUnload |
| Per-test events | Use ExecutionHook instead |
| Custom report generation | Use ReportAdapter instead |