Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Gyrex/Developer Guide/JUnit"

(created)
 
m (Integration Tests)
Line 23: Line 23:
 
public class AllServerTests {
 
public class AllServerTests {
  
@ClassRule
+
  @ClassRule
public static final GyrexServerResource server = new GyrexServerResource();
+
  public static final GyrexServerResource server = new GyrexServerResource();
  
 
}
 
}
 
</pre>
 
</pre>

Revision as of 02:53, 7 October 2012

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;

@RunWith(Suite.class)
@SuiteClasses({ ... })
public class AllServerTests {

  @ClassRule
  public static final GyrexServerResource server = new GyrexServerResource();

}

Back to the top