- 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.
Great post, thank you!
Would you mind sharing your unitTests.py or a cut down version of it? My tests are failing but that isn't failing the build, so it would be good to see how your tests are working.
I haven't used this in a while, so it's possible that something may have changed. If the the PYUnit execution returns a non-zero status, the build _should_ fail.
Hint: on Windows systems you need a semicolon to separate paths in $PYTHONPATH:
Post a Comment