elharo commented on code in PR #597: URL: https://github.com/apache/maven-site/pull/597#discussion_r1931407207
########## content/markdown/plugin-developers/plugin-testing.md: ########## @@ -0,0 +1,154 @@ +<!-- +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. +--> +# Developers Centre - Testing Plugins + +## Introduction + +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. + +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. + +## 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. + +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. Review Comment: and might as wellm delete "(a collection of components used by Apache Maven)" too -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org