- Used commonly available plugins
- Keep the maven structure of test and src files in the appropriate directories.
- Have the tests run in the test phase and fail the build when the tests fail.
The simplest approach I came up with to do this was to use the Exec Maven Plugin by adding the following configuration to your (python) project's POM.
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <executions> <execution> <configuration> <executable>python</executable> <workingDirectory>src/test/python</workingDirectory> <arguments> <argument>unitTests.py</argument> </arguments> <environmentVariables> <PYTHONPATH>../../main/python:$PYTHONPATH</PYTHONPATH> </environmentVariables> </configuration> <id>python-test</id> <phase>test</phase> <goals> <goal>exec</goal> </goals> </execution> </executions> </plugin>
This works well enough. Setting the PYTHONPATH environment variable allows your pyUnit tests to find the modules you are building in the project. What's less than ideal is that, unlike other maven plugins, the person running the build needs to have python installed and configured correctly. (You can allow for some variations between environments. And if you have a developer on your project who doesn't use python, and doesn't want to there is a
This may be obvious to some, if not many, but in case anyone is looking for an answer to how to run unit tests as part of of your maven build, I hope that this is helpful.