-
Notifications
You must be signed in to change notification settings - Fork 11
Example Usage
For example, if my class looks like this:
package com.my.package
class MyClass extends TestPlugin {
def execute(project: MavenProject): Unit =
TestPluginPlugin.mojo().getLog().info("Hello world from the testrunner!")
}
Then my plugin declaration would be as follows. This should be added to the project containing the tests, not the project containing your plugin declaration (this is why it is necessary to add your project as a dependency to the plugin). For example, suppose you wanted to run some tests in Jackrabbit Oak. You must modify the pom.xml inside of Jackrabbit Oak by adding the following plugin. Here we suppose that your example code is a Maven project with the coordinates com.reedoei:my-example-testplugin:1.0-SNAPSHOT
.
<plugin>
<groupId>com.reedoei</groupId>
<artifactId>testrunner-maven-plugin</artifactId>
<version>0.1-SNAPSHOT</version>
<configuration>
<className>com.my.package.MyClass</className>
</configuration>
<dependencies>
<dependency>
<groupId>com.reedoei</groupId>
<artifactId>my-example-testplugin<artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
Then I can run:
mvn testrunner:testplugin
And I will see (in addition to all the standard Maven output):
[INFO] Hello world from the testrunner!
We may modify the above example to run all tests and then print a report to the screen like so:
package com.my.package
class MyClass extends TestPlugin {
override def execute(project: MavenProject): Unit =
RunnerFactory.from(project)
.map(runner => runner.run(TestLocator.tests(project)).map(printResults))
private def printResults(runResult: TestRunResult): Unit =
runResult.results()
forEach((testName, testResult) => println(testName + ": "+ testResult.result))
}
The pom.xml does not need to be changed, as it still contains the correct class name.
Suppose we are using our plugin on a Maven project containing 4 tests in 2 test classes (TestA.test1, TestA.test2, TestB.test1, TestB.test2). Then, running mvn testrunner:testplugin
on this project, we might expect to see the following. Test outcomes have been chosen arbitrarily.
com.package.class.TestA.test1: SKIPPED
com.package.class.TestA.test2: PASS
com.package.class.TestB.test1: ERROR
com.package.class.TestB.test2: PASS