You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/markdown/plugin-developers/plugin-testing.md
+45-2Lines changed: 45 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,9 +35,52 @@ The general wisdom is that your code should be mostly tested with unit tests, bu
35
35
36
36
## Using JUnit alone
37
37
38
-
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`.
38
+
In principle, you can write a unit test of a plugin Mojo the same way you'd write any other JUnit test case.
39
+
40
+
When using injections in your Mojo, you can simply use a mocking framework such as Mockito to create mock instances of the injected dependencies,
41
+
and pass them to the Mojo constructor (if using constructor injection) or set them on the Mojo instance (if using field injection).
42
+
43
+
Simple example using Mockito with constructor 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.
0 commit comments