Skip to main content
Jump to: navigation, search

Gyrex/Developer Guide/JUnit

< Gyrex‎ | Developer Guide
Revision as of 02:54, 7 October 2012 by (Talk | contribs) (Integration Tests)

Tests with JUnit

Gyrex itself is testes with JUnit. The JUnit tests can be run as JUnit OSGi plug-in tests in headless mode. Both, PDE Build and Tycho support such execution of tests. In order to assist developers with running and developing tests, Gyrex provides a few helpers for JUnit.

Integration Tests

Some tests may require a full Gyrex environment to be bootstrapped and running. We call those Integration Tests as they test a certain functionality in the system while operating/integrating with other essential services of the platform (for example, the cloud services backed by ZooKeeper).

Writing integration tests with Gyrex should be done by using the JUnit rules. JUnit rules allow defining dependencies/requirements for JUnit tests. Gyrex provides a rule which ensures that a Gyrex environment is bootstrapped and started before a test is run. Consequently, the server will be stopped after a test is finished. It’s recommended to implement dependencies as a @ClassRule inside a JUnit suite. This groups integration tests together and start the server only once and stop it after executing all tests.

The following example defines a JUnit suite for running integration test.

import org.eclipse.gyrex.context.tests.internal.AllContextTests;
import org.eclipse.gyrex.junit.GyrexServerResource;

import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@SuiteClasses({ /* list test classes here */ })
public class AllServerTests {

  public static final GyrexServerResource server = new GyrexServerResource();


Back to the top