Last updated on 2014-09-07
After my latest round of tooling for the Object-Process Programming project, I have done a lot of development, adding on the way many new unit tests (which I had stopped doing… but after my CI disaster, I am being more careful). I am not a TDD purist/evangelist, but sometimes it is a good methodology. So i created unit tests that failed, fixed the code, ran the tests, green, done. And all the time I thought that the test were being executed by Maven every time I checked in my projects. I was wrong :-(. I found this when I added a test that failed, executed Maven, and the build succeeded. WTF?. Having a build that succeeds when unit tests fail is worse than having no build at all!
As usual, what happened is that Tycho builds execute unit tests differently than regular Maven builds (just like it treats every other thing differently).
What must done is explained in high level here. Basically, for each plug-in (or bundle) we want to test, we have to create a new plug-in project (usually named “plugin-name.test”). This project must be configured using the required Tycho configuration, using eclipse-test-plugin
as the Maven packaging type and the unit tests added to the src
directory. Now you can execute mvn integration-test
to run your unit tests. If you also add the tests plug-in to your main build file (as a sub-module for example), the test are executed every build.
Another possible way to do the same thing (but a bit better) is to create a plug-in fragment. A fragment is an extension of an existing plug-in, therefore it shares dependencies (DRI), and removes the necessity to export all internal plug-in classes just for testing.
The project where I implemented this solution can be found on GitHub. Enjoy

Be First to Comment