Testing a Plug-in
If you're writing a plug-in for general consumption, it would be good if you could ensure that it is working fine. You don't want to release something buggy, right? This lab will show you how to write automated tests for your plug-in.
How do I do that?
You can write two types of tests: Java unit tests and functional tests. Writing
Java unit tests makes sense only if your plug-in is relying on Java
source code. You add JUnit tests to your plug-in project just as you
do for any Maven project: you add them to an src/test directory defined using the
unitTestSourceDirectory element in
your project.xml file. When you
execute the plugin:install goal,
your unit tests will run automatically.
As most Maven plug-ins rely on Jelly script, it makes more sense
to focus on writing functional tests than it does to focus on JUnit
tests. The Plugin plug-in has a special plugin:test goal which automatically starts
your functional tests, provided you have put them in the src/plugin-test directory. A functional
test is simply a Maven project that you put in src/plugin-test. This Maven test project
has to meet only one condition: it must have a custom goal named
testPlugin that you write in its
maven.xml file. Under the hood,
this is the goal that will be called when you execute the plugin:test goal.
As you might need several functional tests for your plug-in, the best practice is to set up a Multiproject project in src/plugin-test. For example, for the Jarexec plug-in you might want ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access