[Q&A Friday] How to Test Operations?

Here's an interesting question from Narcis. He asks how he can test an operation. Quality is of paramount importance here at Nuxeo, as you may have gathered from a previous blog post. Most of us use TDD (Test-driven development), and hence rely heavily on unit tests. We try to make developers' lives easier by giving them different test cases or runners to use in their tests. Take a look at our documentation on unit tests.

As Benjamin said in his answer, there are a lot of examples in our source code. Let's go through one of them. I've chosen the simple LoginAsTest.

To configure the way the test is launched the Nuxeo test framework is using the concept of test features. A test feature is a special class that is notified by the runner about the different life cycle events of the execution so that it may customize the way the test is setup or test methods are run. Test features are configurable through annotations. Each test feature is able to use its own defined annotations to configure the test. Also a feature may provide additional objects to be injected in tests using Guice.

And finally @deploy, one of the most important annotation since it allows you to deploy other nuxeo bundles. This is what we actually use in the different features. That's why you can inject the directory service or the user manager when you have the PlatformFeature. Here we deploy the automation bundles as well the web-common and login bundles to test the loginAs operation.

I previously mentioned injection. We use Guice to inject nuxeo services as well as other objects. This is also described in our documentation.

And finally you have the usual Junit annotations, @Before to execute code before a test, and @test to identify the test methods.

Don't hesitate to look at the range of features we have on offer. Here is a list of some of the most important ones:

WebDriver Feature

Runtime Feature

Jetty Feature

Core Feature

Platform Feature

WebEngine Feature

Nuxeo Distribution Feature

A special thanks to Damien Metzler and his team who contributed most of the junit4/Guice testing framework, and to Bogdan who integrated it into nuxeo-runtime.