From 83d1a188c61b37760210f99aa13027e94c967cc7 Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Mon, 16 Dec 2024 15:36:00 +0100 Subject: [PATCH 1/9] conversion from apt to markdown for plugin-testing --- .../apt/plugin-developers/plugin-testing.apt | 173 ------------------ .../plugin-developers/plugin-testing.md | 154 ++++++++++++++++ 2 files changed, 154 insertions(+), 173 deletions(-) delete mode 100644 content/apt/plugin-developers/plugin-testing.apt create mode 100644 content/markdown/plugin-developers/plugin-testing.md diff --git a/content/apt/plugin-developers/plugin-testing.apt b/content/apt/plugin-developers/plugin-testing.apt deleted file mode 100644 index 803342c281..0000000000 --- a/content/apt/plugin-developers/plugin-testing.apt +++ /dev/null @@ -1,173 +0,0 @@ - ------ - Developers centre - Testing Plugins Strategies - ------ - Vincent Siveton - ------ - 2008-01-01 - 2015-06-16 - ------ - -~~ Licensed to the Apache Software Foundation (ASF) under one -~~ or more contributor license agreements. See the NOTICE file -~~ distributed with this work for additional information -~~ regarding copyright ownership. The ASF licenses this file -~~ to you under the Apache License, Version 2.0 (the -~~ "License"); you may not use this file except in compliance -~~ with the License. You may obtain a copy of the License at -~~ -~~ http://www.apache.org/licenses/LICENSE-2.0 -~~ -~~ Unless required by applicable law or agreed to in writing, -~~ software distributed under the License is distributed on an -~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -~~ KIND, either express or implied. See the License for the -~~ specific language governing permissions and limitations -~~ under the License. - -~~ NOTE: For help with the syntax of this file, see: -~~ http://maven.apache.org/doxia/references/apt-format.html - -Introduction - - Currently, Maven only supports unit testing out of the box. This document is intended to help Maven Developers - test plugins with unit tests, integration tests, and functional tests. - -~~ <> For a review of different strategies and tools, please refer to {{{http://docs.codehaus.org/display/MAVENUSER/Review+of+Plugin+Testing+Strategies}Review of Plugin Testing Strategies}} - -Testing Styles: Unit Testing vs. Functional/Integration Testing - - A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. - - A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project. Normally this requires you to construct special dummy Maven projects with real POM files. Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build. Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests. - - The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests. - -Unit Tests - -* Using JUnit alone - - In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case, by writing a class that <<>>. - - However, many mojo methods need more information to work properly. For example, you'll probably need to inject a reference - to a <<>>, so your mojo can query project variables. - -* Using PlexusTestCase - - Mojo variables are injected by Guice, sometimes with a Plexus adapter to support the legacy <<<@Component>>> annotation. - Currently some mojos are fully guicified with constructor - injection, while others that have not yet been converted use Plexus field injection. - - Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies - by having the test class extend <<>> and calling the <>> method to instantiate the mojo. - Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending <<>>. - These dependencies can be Mockito mocks or instances of the actual model classes. If a particular test does not access the injected - field — that is, it's only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. - - With that said, if you need to inject Maven objects into your mojo, you'll probably prefer to use the maven-plugin-testing-harness. - -* maven-plugin-testing-harness - - The {{{/plugin-testing/maven-plugin-testing-harness/}maven-plugin-testing-harness}} - is explicitly intended to test the <<>> implementation. - - In general, you need to include <<>> as a test-scoped dependency, - and create a MojoTest (by convention) class which <<>>. - -+-----+ -... - - ... - - org.apache.maven.plugin-testing - maven-plugin-testing-harness - 3.3.0 - test - - ... - -... -+-----+ -+-----+ -public class YourMojoTest - extends AbstractMojoTestCase -{ - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - // required for mojo lookups to work - super.setUp(); - } - - /** - * @throws Exception - */ - public void testMojoGoal() throws Exception - { - File testPom = new File( getBasedir(), - "src/test/resources/unit/basic-test/basic-test-plugin-config.xml" ); - - YourMojo mojo = (YourMojo) lookupMojo( "yourGoal", testPom ); - - assertNotNull( mojo ); - } -} -+-----+ - - For more information, refer to {{{https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness}Maven Plugin Harness Wiki}} - -Integration/Functional testing - -* maven-verifier - - maven-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts. - It also provides a <<>>, which extracts a Maven project from the src/test/resources directory into a temporary working directory - where you can do tricky stuff with it. Follow the {{{/shared/maven-verifier/getting-started.html}Getting Started}} guide to learn more about creating - maven-verifier tests. - - Maven itself uses maven-verifier to run its core integration tests. For more information, see {{{https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test}Creating a Maven Integration Test}}. - - <>: maven-verifier and maven-verifier-plugin sound similar, but are totally different unrelated pieces of code. maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. You could use it for functional testing, but you may need more features than maven-verifier-plugin provides. - -* maven-invoker-plugin - - You can use {{{https://maven.apache.org/plugins/maven-invoker-plugin/}maven-invoker-plugin}} - to invoke Maven and to provide some BeanShell/Groovy tests. Tests written in - this way don't run under JUnit/TestNG; instead, they're run by Maven itself. - - You can take a look at the {{{https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/}maven-install-plugin}} - to see how integration tests are written. - -+-----+ - - ... - - - - org.apache.maven.plugins - maven-invoker-plugin - 1.10 - - src/it - - **/pom.xml - - verify - - - - - run - - - - - ... - - - ... - -+-----+ - diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md new file mode 100644 index 0000000000..adf604eca8 --- /dev/null +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -0,0 +1,154 @@ +--- +title: Developers centre - Testing Plugins Strategies +author: + - Vincent Siveton +date: 2008-01-01 +2015-06-16 +--- + + + + + + + + + + + + + + + + + + + +# Introduction + +Currently, Maven only supports unit testing out of the box\. This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests\. + + +# Testing Styles: Unit Testing vs\. Functional/Integration Testing + +A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment\. A mojo unit test does not attempt to run your plugin in the context of a real Maven build\. Unit tests are designed to be fast\. + +A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project\. Normally this requires you to construct special dummy Maven projects with real POM files\. Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build\. Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests\. + +The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests\. + +# Unit Tests + +## Using JUnit alone + +In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case, by writing a class that `extends TestCase`\. + +However, many mojo methods need more information to work properly\. For example, you'll probably need to inject a reference to a `MavenProject`, so your mojo can query project variables\. + +## Using PlexusTestCase + +Mojo variables are injected by Guice, sometimes with a Plexus adapter to support the legacy `@Component` annotation\. Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection\. + +Both Guice\-based and Plexus\-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup\(\)**> method to instantiate the mojo\. Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`\. These dependencies can be Mockito mocks or instances of the actual model classes\. If a particular test does not access the injected field — that is, it's only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument\. + +With that said, if you need to inject Maven objects into your mojo, you'll probably prefer to use the maven\-plugin\-testing\-harness\. + +## maven\-plugin\-testing\-harness + +The [maven\-plugin\-testing\-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the `org.apache.maven.reporting.AbstractMavenReport#execute()` implementation\. + +In general, you need to include `maven-plugin-testing-harness` as a test\-scoped dependency, and create a MojoTest \(by convention\) class which `extends AbstractMojoTestCase`\. + +```unknown +... + + ... + + org.apache.maven.plugin-testing + maven-plugin-testing-harness + 3.3.0 + test + + ... + +... +``` + +```unknown +public class YourMojoTest + extends AbstractMojoTestCase +{ + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception + { + // required for mojo lookups to work + super.setUp(); + } + + /** + * @throws Exception + */ + public void testMojoGoal() throws Exception + { + File testPom = new File( getBasedir(), + "src/test/resources/unit/basic-test/basic-test-plugin-config.xml" ); + + YourMojo mojo = (YourMojo) lookupMojo( "yourGoal", testPom ); + + assertNotNull( mojo ); + } +} +``` + +For more information, refer to [Maven Plugin Harness Wiki](https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness) + +# Integration/Functional testing + +## maven\-verifier + +maven\-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts\. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it\. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven\-verifier tests\. + +Maven itself uses maven\-verifier to run its core integration tests\. For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test)\. + +**Note**: maven\-verifier and maven\-verifier\-plugin sound similar, but are totally different unrelated pieces of code\. maven\-verifier\-plugin simply verifies the existence/absence of files on the filesystem\. You could use it for functional testing, but you may need more features than maven\-verifier\-plugin provides\. + +## maven\-invoker\-plugin + +You can use [maven\-invoker\-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests\. Tests written in this way don't run under JUnit/TestNG; instead, they're run by Maven itself\. + +You can take a look at the [maven\-install\-plugin](https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/) to see how integration tests are written\. + +```unknown + + ... + + + + org.apache.maven.plugins + maven-invoker-plugin + 1.10 + + src/it + + **/pom.xml + + verify + + + + + run + + + + + ... + + + ... + +``` + From bbbe2fdcdc9a2b4f935995e2eb66a932eb81a37d Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Tue, 17 Dec 2024 09:54:19 +0100 Subject: [PATCH 2/9] manual markdown adoption and JUnit5 testing docu --- .../plugin-developers/plugin-testing.md | 134 ++++++++++-------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index adf604eca8..7cdd00afa3 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -1,72 +1,65 @@ ---- -title: Developers centre - Testing Plugins Strategies -author: - - Vincent Siveton -date: 2008-01-01 -2015-06-16 ---- + - - - - - - - - - - - - - - - - - -# Introduction + http://www.apache.org/licenses/LICENSE-2.0 -Currently, Maven only supports unit testing out of the box\. This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests\. +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> +# Developers Centre - Testing Plugins Strategies - -# Testing Styles: Unit Testing vs\. Functional/Integration Testing +## Introduction -A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment\. A mojo unit test does not attempt to run your plugin in the context of a real Maven build\. Unit tests are designed to be fast\. +Currently, Maven only supports unit testing out of the box. This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests. -A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project\. Normally this requires you to construct special dummy Maven projects with real POM files\. Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build\. Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests\. +## Testing Styles: Unit Testing vs. Functional/Integration Testing -The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests\. +A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. -# Unit Tests +A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project. Normally this requires you to construct special dummy Maven projects with real POM files. Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build. Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests. -## Using JUnit alone +The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests. -In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case, by writing a class that `extends TestCase`\. +## Unit Tests -However, many mojo methods need more information to work properly\. For example, you'll probably need to inject a reference to a `MavenProject`, so your mojo can query project variables\. +### Using JUnit alone -## Using PlexusTestCase +In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case, by writing a class that `extends TestCase`. -Mojo variables are injected by Guice, sometimes with a Plexus adapter to support the legacy `@Component` annotation\. Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection\. +However, many mojo methods need more information to work properly. For example, you'll probably need to inject a reference to a `MavenProject`, so your mojo can query project variables. -Both Guice\-based and Plexus\-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup\(\)**> method to instantiate the mojo\. Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`\. These dependencies can be Mockito mocks or instances of the actual model classes\. If a particular test does not access the injected field — that is, it's only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument\. +### Using PlexusTestCase -With that said, if you need to inject Maven objects into your mojo, you'll probably prefer to use the maven\-plugin\-testing\-harness\. +Mojo variables are injected by Guice, sometimes with a Plexus adapter to support the legacy `@Component` annotation. Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection. -## maven\-plugin\-testing\-harness +Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. These dependencies can be Mockito mocks or instances of the actual model classes. If a particular test does not access the injected field — that is, it's only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. -The [maven\-plugin\-testing\-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the `org.apache.maven.reporting.AbstractMavenReport#execute()` implementation\. +With that said, if you need to inject Maven objects into your mojo, you'll probably prefer to use the maven-plugin-testing-harness. -In general, you need to include `maven-plugin-testing-harness` as a test\-scoped dependency, and create a MojoTest \(by convention\) class which `extends AbstractMojoTestCase`\. +### Using the maven-plugin-testing-harness -```unknown +The [maven-plugin-testing-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the `org.apache.maven.reporting.AbstractMavenReport#execute()` implementation. + +In general, you need to include `maven-plugin-testing-harness` as a test-scoped dependency. + +```xml ... ... org.apache.maven.plugin-testing maven-plugin-testing-harness - 3.3.0 + 3.4.0 test ... @@ -74,7 +67,34 @@ In general, you need to include `maven-plugin-testing-harness` as a test\-scoped ... ``` -```unknown +#### JUnit5 style tests + +JUnit5 (jupiter) uses an Extension framework for which the `MojoExtension` is provided by the `maven-plugin-testing-harness`. +You can annotate your JUnit5 test with `@MojoTest` and with that leverage the `MojoExtension` to inject the Mojo under test. +This functionality got introduced with version `3.4.0` of the `maven-plugin-testing-harness`. +Below is an example: + +```java +@MojoTest +public class YourMojoTest { + + private static final String POM = "src/test/resources/unit/basic-test/basic-test-plugin-config.xml"; + + @Test + @InjectMojo(goal = "generate", pom = POM) + void simpleMojo(YourMojo mojo) { + assertNotNull( mojo ); + } +} +``` + +#### deprecated JUnit4 style tests +There is the deprecated way to write tests using JUnit4 style. +This is not recommended, but you can still use it on Maven 3. +For Maven 4 only JUnit4 style tests will not be supported. +Below is an example: + +```java public class YourMojoTest extends AbstractMojoTestCase { @@ -102,27 +122,26 @@ public class YourMojoTest } ``` +#### more information For more information, refer to [Maven Plugin Harness Wiki](https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness) -# Integration/Functional testing +## Integration/Functional testing -## maven\-verifier +### maven-verifier -maven\-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts\. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it\. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven\-verifier tests\. +maven-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven-verifier tests. -Maven itself uses maven\-verifier to run its core integration tests\. For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test)\. +Maven itself uses maven-verifier to run its core integration tests. For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test). -**Note**: maven\-verifier and maven\-verifier\-plugin sound similar, but are totally different unrelated pieces of code\. maven\-verifier\-plugin simply verifies the existence/absence of files on the filesystem\. You could use it for functional testing, but you may need more features than maven\-verifier\-plugin provides\. +**Note**: maven-verifier and maven-verifier-plugin sound similar, but are totally different unrelated pieces of code. maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. You could use it for functional testing, but you may need more features than maven-verifier-plugin provides. -## maven\-invoker\-plugin +### maven-invoker-plugin -You can use [maven\-invoker\-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests\. Tests written in this way don't run under JUnit/TestNG; instead, they're run by Maven itself\. +You can use [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests. Tests written in this way don't run under JUnit/TestNG; instead, they're run by Maven itself. -You can take a look at the [maven\-install\-plugin](https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/) to see how integration tests are written\. +You can take a look at the [maven-install-plugin](https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/) to see how integration tests are written. -```unknown - +```xml ... @@ -149,6 +168,5 @@ You can take a look at the [maven\-install\-plugin](https://svn.apache.org/repos ... - ``` From 9d136d09a574a8632709e779024ec1158c83327b Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Wed, 18 Dec 2024 16:33:52 +0100 Subject: [PATCH 3/9] eprecated JUnit4 style tests docu adoption --- content/markdown/plugin-developers/plugin-testing.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 7cdd00afa3..9c248e3697 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -91,7 +91,8 @@ public class YourMojoTest { #### deprecated JUnit4 style tests There is the deprecated way to write tests using JUnit4 style. This is not recommended, but you can still use it on Maven 3. -For Maven 4 only JUnit4 style tests will not be supported. +For Maven 4 only JUnit5 style tests are available and JUnit4 will not be supported there anymore. +Please consider migrating your JUnit4 MojoTests to JUnit5. Below is an example: ```java From ec31f18264270886cc488c854742b09701d4bdec Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Tue, 31 Dec 2024 16:41:52 +0100 Subject: [PATCH 4/9] review comments from Bukama, slawekjaranowski and elharo --- .../plugin-developers/plugin-testing.md | 66 +++++++++++-------- 1 file changed, 40 insertions(+), 26 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 9c248e3697..90af0c61bb 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -20,13 +20,18 @@ under the License. ## Introduction -Currently, Maven only supports unit testing out of the box. This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests. +Currently, Maven only supports unit testing out of the box. +This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests. ## Testing Styles: Unit Testing vs. Functional/Integration Testing -A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. +A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. +A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. -A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project. Normally this requires you to construct special dummy Maven projects with real POM files. Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build. Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests. +A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project. +Normally this requires you to construct special dummy Maven projects with real POM files. +Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build. +Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests. The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests. @@ -34,21 +39,26 @@ The general wisdom is that your code should be mostly tested with unit tests, bu ### Using JUnit alone -In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case, by writing a class that `extends TestCase`. +In principle, you can write a unit test of a plugin Mojo the same way you’d write any other JUnit test case. -However, many mojo methods need more information to work properly. For example, you'll probably need to inject a reference to a `MavenProject`, so your mojo can query project variables. +However, many mojo methods need more information to work properly. +For example, you’ll probably need to inject or mock a reference to a `MavenProject`, so your mojo can query project variables. ### Using PlexusTestCase -Mojo variables are injected by Guice, sometimes with a Plexus adapter to support the legacy `@Component` annotation. Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection. +Mojo variables are injected by Guice (an open-source software framework for the Java platform), sometimes with a Codehaus Plexus (a collection of components used by Apache Maven) adapter to support the legacy `@Component` annotation. +Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection. -Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. These dependencies can be Mockito mocks or instances of the actual model classes. If a particular test does not access the injected field — that is, it's only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. +Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. +Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. +These dependencies can be Mockito mocks or instances of the actual model classes. +If a particular test does not access the injected field — that is, it’s only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. -With that said, if you need to inject Maven objects into your mojo, you'll probably prefer to use the maven-plugin-testing-harness. +With that said, if you need to inject Maven objects into your mojo, you’ll probably prefer to use the maven-plugin-testing-harness. ### Using the maven-plugin-testing-harness -The [maven-plugin-testing-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the `org.apache.maven.reporting.AbstractMavenReport#execute()` implementation. +The [maven-plugin-testing-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the implementation of the `org.apache.maven.reporting.AbstractMavenReport#execute()` method. In general, you need to include `maven-plugin-testing-harness` as a test-scoped dependency. @@ -59,6 +69,7 @@ In general, you need to include `maven-plugin-testing-harness` as a test-scoped org.apache.maven.plugin-testing maven-plugin-testing-harness + 3.4.0 test @@ -67,11 +78,11 @@ In general, you need to include `maven-plugin-testing-harness` as a test-scoped ... ``` -#### JUnit5 style tests +#### JUnit Jupiter (JUnit 5) style tests -JUnit5 (jupiter) uses an Extension framework for which the `MojoExtension` is provided by the `maven-plugin-testing-harness`. -You can annotate your JUnit5 test with `@MojoTest` and with that leverage the `MojoExtension` to inject the Mojo under test. -This functionality got introduced with version `3.4.0` of the `maven-plugin-testing-harness`. +JUnit Jupiter uses an extension framework for which the `MojoExtension` is provided by the `maven-plugin-testing-harness`. +You can annotate your JUnit Jupiter test with `@MojoTest` and with that leverage the `MojoExtension` to inject the Mojo under test. +This functionality was introduced in version `3.4.0` of the `maven-plugin-testing-harness`. Below is an example: ```java @@ -88,11 +99,11 @@ public class YourMojoTest { } ``` -#### deprecated JUnit4 style tests -There is the deprecated way to write tests using JUnit4 style. +#### JUnit 4 style tests (deprecated) +There is the deprecated way to write tests using JUnit 4 style. This is not recommended, but you can still use it on Maven 3. -For Maven 4 only JUnit5 style tests are available and JUnit4 will not be supported there anymore. -Please consider migrating your JUnit4 MojoTests to JUnit5. +For Maven 4 only JUnit Jupiter style tests are available and JUnit 4 is not supported there anymore. +Please consider migrating your JUnit 4 style MojoTests to JUnit Jupiter tests. Below is an example: ```java @@ -108,9 +119,6 @@ public class YourMojoTest super.setUp(); } - /** - * @throws Exception - */ public void testMojoGoal() throws Exception { File testPom = new File( getBasedir(), @@ -123,22 +131,28 @@ public class YourMojoTest } ``` -#### more information -For more information, refer to [Maven Plugin Harness Wiki](https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness) +#### More information +For more information, please refer to the [Maven Plugin Harness Wiki](https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness) ## Integration/Functional testing ### maven-verifier -maven-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven-verifier tests. +maven-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts. +It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it. +Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven-verifier tests. -Maven itself uses maven-verifier to run its core integration tests. For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test). +Maven itself uses maven-verifier to run its core integration tests. +For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test). -**Note**: maven-verifier and maven-verifier-plugin sound similar, but are totally different unrelated pieces of code. maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. You could use it for functional testing, but you may need more features than maven-verifier-plugin provides. +**Note**: maven-verifier and maven-verifier-plugin sound similar, but are totally different unrelated pieces of code. +maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. +You could use it for functional testing, but you may need more features than maven-verifier-plugin provides. ### maven-invoker-plugin -You can use [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests. Tests written in this way don't run under JUnit/TestNG; instead, they're run by Maven itself. +You can use [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests. +Tests written in this way don’t run under JUnit/TestNG; instead, they’re run by Maven itself. You can take a look at the [maven-install-plugin](https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/) to see how integration tests are written. From 217539231804057e19304e6d3d4e47295917f8f3 Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Mon, 6 Jan 2025 13:32:10 +0100 Subject: [PATCH 5/9] further review comments from Bukama --- .../markdown/plugin-developers/plugin-testing.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 90af0c61bb..a1e861a839 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -138,23 +138,25 @@ For more information, please refer to the [Maven Plugin Harness Wiki](https://cw ### maven-verifier -maven-verifier tests are run using JUnit, and provide a simple class allowing you to launch Maven and assert on its log file and built artifacts. +maven-verifier tests are run using JUnit. +They provide a simple class allowing you to launch Maven and assert on its log file and its build artifacts. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven-verifier tests. Maven itself uses maven-verifier to run its core integration tests. For more information, see [Creating a Maven Integration Test](https://cwiki.apache.org/confluence/display/MAVEN/Creating+a+Maven+Integration+Test). -**Note**: maven-verifier and maven-verifier-plugin sound similar, but are totally different unrelated pieces of code. -maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. -You could use it for functional testing, but you may need more features than maven-verifier-plugin provides. +**Note**: maven-verifier and maven-verifier-plugin sound similar, but are totally different and unrelated pieces of code. +The maven-verifier-plugin simply verifies the existence/absence of files on the filesystem. +You could use it for functional testing, but you may need more features than the maven-verifier-plugin provides. ### maven-invoker-plugin -You can use [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests. -Tests written in this way don’t run under JUnit/TestNG; instead, they’re run by Maven itself. +You can use the [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) to invoke Maven and to provide some BeanShell/Groovy tests. +Tests written in this way don’t run with a testing framework. +Instead, they’re run by Maven itself. -You can take a look at the [maven-install-plugin](https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-install-plugin/src/it/) to see how integration tests are written. +You can take a look at the [maven-install-plugin](https://github.com/apache/maven-install-plugin/tree/master/src/it) to see how integration tests are written. ```xml ... From 4056ce2e247a2afd0e296fbb3627ea17bfad44f9 Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Tue, 7 Jan 2025 10:14:56 +0100 Subject: [PATCH 6/9] review comments from elharo --- .../plugin-developers/plugin-testing.md | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index a1e861a839..5e3834e916 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -16,11 +16,10 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -# Developers Centre - Testing Plugins Strategies +# Developers Centre - Testing Plugins ## Introduction -Currently, Maven only supports unit testing out of the box. This document is intended to help Maven Developers test plugins with unit tests, integration tests, and functional tests. ## Testing Styles: Unit Testing vs. Functional/Integration Testing @@ -28,10 +27,7 @@ This document is intended to help Maven Developers test plugins with unit tests, A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. -A functional/integration test attempts to use a mojo in a real Maven build, by launching a real instance of Maven in a real project. -Normally this requires you to construct special dummy Maven projects with real POM files. -Often this requires you to have already installed your plugin into your local repository so it can be used in a real Maven build. -Functional tests run much more slowly than unit tests, but they can catch bugs that you may not catch with unit tests. +Functional tests run much more slowly than unit tests, but they can catch bugs or detect issues that you may not catch with unit tests. The general wisdom is that your code should be mostly tested with unit tests, but should also have some functional tests. @@ -41,16 +37,16 @@ The general wisdom is that your code should be mostly tested with unit tests, bu In principle, you can write a unit test of a plugin Mojo the same way you’d write any other JUnit test case. -However, many mojo methods need more information to work properly. +However, many mojo methods need more dependencies to work properly. For example, you’ll probably need to inject or mock a reference to a `MavenProject`, so your mojo can query project variables. ### Using PlexusTestCase -Mojo variables are injected by Guice (an open-source software framework for the Java platform), sometimes with a Codehaus Plexus (a collection of components used by Apache Maven) adapter to support the legacy `@Component` annotation. +Mojo variables are injected by Guice (an open-source software framework for the Java platform), sometimes with a Codehaus Plexus (a collection of components used by Apache Maven) adapter. Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection. Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. -Tests for fully Guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. +Tests for fully guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. These dependencies can be Mockito mocks or instances of the actual model classes. If a particular test does not access the injected field — that is, it’s only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. @@ -102,7 +98,8 @@ public class YourMojoTest { #### JUnit 4 style tests (deprecated) There is the deprecated way to write tests using JUnit 4 style. This is not recommended, but you can still use it on Maven 3. -For Maven 4 only JUnit Jupiter style tests are available and JUnit 4 is not supported there anymore. +For Maven 4 only JUnit Jupiter style tests are available. +JUnit 4 is no longer supported. Please consider migrating your JUnit 4 style MojoTests to JUnit Jupiter tests. Below is an example: @@ -110,36 +107,24 @@ Below is an example: public class YourMojoTest extends AbstractMojoTestCase { - /** - * @see junit.framework.TestCase#setUp() - */ - protected void setUp() throws Exception - { - // required for mojo lookups to work - super.setUp(); - } - public void testMojoGoal() throws Exception { File testPom = new File( getBasedir(), "src/test/resources/unit/basic-test/basic-test-plugin-config.xml" ); - YourMojo mojo = (YourMojo) lookupMojo( "yourGoal", testPom ); + YourMojo mojo = (YourMojo) lookupMojo("yourGoal", testPom); - assertNotNull( mojo ); + assertNotNull(mojo); } } ``` -#### More information -For more information, please refer to the [Maven Plugin Harness Wiki](https://cwiki.apache.org/confluence/display/MAVENOLD/Maven+Plugin+Harness) - ## Integration/Functional testing -### maven-verifier +### Maven Verifier Component -maven-verifier tests are run using JUnit. -They provide a simple class allowing you to launch Maven and assert on its log file and its build artifacts. +The Apache Maven Verifier Component (maven-verifier) tests are run using JUnit. +It provides a simple class allowing you to launch Maven and assert on its log file and its build artifacts. It also provides a `ResourceExtractor`, which extracts a Maven project from the src/test/resources directory into a temporary working directory where you can do tricky stuff with it. Follow the [Getting Started](/shared/maven-verifier/getting-started.html) guide to learn more about creating maven-verifier tests. From 3083bd07d8fe7e5f7c4a9e74d22dd156896437b5 Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Tue, 7 Jan 2025 10:43:51 +0100 Subject: [PATCH 7/9] further adoptions for comments from elharo --- .../plugin-developers/plugin-testing.md | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 5e3834e916..8b7b8bc06d 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -43,7 +43,6 @@ For example, you’ll probably need to inject or mock a reference to a `MavenPro ### Using PlexusTestCase Mojo variables are injected by Guice (an open-source software framework for the Java platform), sometimes with a Codehaus Plexus (a collection of components used by Apache Maven) adapter. -Currently some mojos are fully guicified with constructor injection, while others that have not yet been converted use Plexus field injection. Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. Tests for fully guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. @@ -54,9 +53,9 @@ With that said, if you need to inject Maven objects into your mojo, you’ll pro ### Using the maven-plugin-testing-harness -The [maven-plugin-testing-harness](/plugin-testing/maven-plugin-testing-harness/) is explicitly intended to test the implementation of the `org.apache.maven.reporting.AbstractMavenReport#execute()` method. +The [maven-plugin-testing-harness](/plugin-testing/maven-plugin-testing-harness/) is designed to test the implementation of the `org.apache.maven.reporting.AbstractMavenReport#execute()` method. -In general, you need to include `maven-plugin-testing-harness` as a test-scoped dependency. +You have to include `maven-plugin-testing-harness` as a test-scoped dependency. ```xml ... @@ -76,8 +75,8 @@ In general, you need to include `maven-plugin-testing-harness` as a test-scoped #### JUnit Jupiter (JUnit 5) style tests -JUnit Jupiter uses an extension framework for which the `MojoExtension` is provided by the `maven-plugin-testing-harness`. -You can annotate your JUnit Jupiter test with `@MojoTest` and with that leverage the `MojoExtension` to inject the Mojo under test. +JUnit Jupiter uses an extension framework for which `MojoExtension` is provided by the `maven-plugin-testing-harness`. +You can annotate your JUnit Jupiter test with `@MojoTest`; then inject the mojo under test into the test method with the `@InjectMojo` annotation. This functionality was introduced in version `3.4.0` of the `maven-plugin-testing-harness`. Below is an example: @@ -96,28 +95,9 @@ public class YourMojoTest { ``` #### JUnit 4 style tests (deprecated) -There is the deprecated way to write tests using JUnit 4 style. -This is not recommended, but you can still use it on Maven 3. +For Maven 3 there is the deprecated way to write tests using JUnit 4 style. For Maven 4 only JUnit Jupiter style tests are available. JUnit 4 is no longer supported. -Please consider migrating your JUnit 4 style MojoTests to JUnit Jupiter tests. -Below is an example: - -```java -public class YourMojoTest - extends AbstractMojoTestCase -{ - public void testMojoGoal() throws Exception - { - File testPom = new File( getBasedir(), - "src/test/resources/unit/basic-test/basic-test-plugin-config.xml" ); - - YourMojo mojo = (YourMojo) lookupMojo("yourGoal", testPom); - - assertNotNull(mojo); - } -} -``` ## Integration/Functional testing From 8cc434dc6557ae050bc8f66fac88a0c3577933da Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Tue, 7 Jan 2025 10:44:53 +0100 Subject: [PATCH 8/9] parentheses around injectMojo --- content/markdown/plugin-developers/plugin-testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 8b7b8bc06d..0403c4ee2d 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -89,7 +89,7 @@ public class YourMojoTest { @Test @InjectMojo(goal = "generate", pom = POM) void simpleMojo(YourMojo mojo) { - assertNotNull( mojo ); + assertNotNull(mojo); } } ``` From 668d60f592fe9687608c39fc861fd4822858b2a6 Mon Sep 17 00:00:00 2001 From: Harald Aamot Date: Wed, 8 Jan 2025 09:28:23 +0100 Subject: [PATCH 9/9] further review from elharo --- .../plugin-developers/plugin-testing.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/content/markdown/plugin-developers/plugin-testing.md b/content/markdown/plugin-developers/plugin-testing.md index 0403c4ee2d..70cbde40bb 100644 --- a/content/markdown/plugin-developers/plugin-testing.md +++ b/content/markdown/plugin-developers/plugin-testing.md @@ -24,8 +24,8 @@ This document is intended to help Maven Developers test plugins with unit tests, ## Testing Styles: Unit Testing vs. Functional/Integration Testing -A unit test attempts to verify a mojo as an isolated unit, by mocking out the rest of the Maven environment. -A mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. +A unit test attempts to verify a Mojo as an isolated unit, by mocking out the rest of the Maven environment. +A Mojo unit test does not attempt to run your plugin in the context of a real Maven build. Unit tests are designed to be fast. Functional tests run much more slowly than unit tests, but they can catch bugs or detect issues that you may not catch with unit tests. @@ -37,19 +37,19 @@ The general wisdom is that your code should be mostly tested with unit tests, bu In principle, you can write a unit test of a plugin Mojo the same way you’d write any other JUnit test case. -However, many mojo methods need more dependencies to work properly. -For example, you’ll probably need to inject or mock a reference to a `MavenProject`, so your mojo can query project variables. +However, many Mojo methods need more dependencies to work properly. +For example, you’ll probably need to inject a reference to a `MavenProject`, so your Mojo can query project variables. ### Using PlexusTestCase Mojo variables are injected by Guice (an open-source software framework for the Java platform), sometimes with a Codehaus Plexus (a collection of components used by Apache Maven) adapter. -Both Guice-based and Plexus-based mojos rely on the Guice Plexus adapter to inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the mojo. -Tests for fully guicified mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. +Both Guice-based and Plexus-based Mojos inject dependencies by having the test class extend `PlexusTestCase` and calling the **lookup()** method to instantiate the Mojo. +Tests for fully guicified Mojos can also inject dependencies directly into the constructor without extending `PlexusTestCase`. These dependencies can be Mockito mocks or instances of the actual model classes. -If a particular test does not access the injected field — that is, it’s only injected to fulfill the constructor signature — you can usually also pass null as the value of that argument. +If a particular test does not access the injected field — that is, it’s only injected to fulfill the constructor signature — you can usually pass null as the value of that argument. -With that said, if you need to inject Maven objects into your mojo, you’ll probably prefer to use the maven-plugin-testing-harness. +With that said, if you need to inject Maven objects into your Mojo, you’ll probably prefer to use the maven-plugin-testing-harness. ### Using the maven-plugin-testing-harness @@ -76,7 +76,7 @@ You have to include `maven-plugin-testing-harness` as a test-scoped dependency. #### JUnit Jupiter (JUnit 5) style tests JUnit Jupiter uses an extension framework for which `MojoExtension` is provided by the `maven-plugin-testing-harness`. -You can annotate your JUnit Jupiter test with `@MojoTest`; then inject the mojo under test into the test method with the `@InjectMojo` annotation. +You can annotate your JUnit Jupiter test with `@MojoTest`; then inject the Mojo under test into the test method with the `@InjectMojo` annotation. This functionality was introduced in version `3.4.0` of the `maven-plugin-testing-harness`. Below is an example: