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 "Riena/Getting Started with Controller Tests"

(Testing Ridget behavior)
(Testing scenarios)
Line 21: Line 21:
  
 
== Testing scenarios ==
 
== Testing scenarios ==
 +
This section coves some in depth examples on how to test your Controllers. More examples are found in org.eclipse.riena.client.controller.test.
 +
 
=== Testing Ridget behavior ===
 
=== Testing Ridget behavior ===
 
Here is a short example to test simple correlations between Ridgets (see ChoiceSubModuleController from the Riena Example Client):
 
Here is a short example to test simple correlations between Ridgets (see ChoiceSubModuleController from the Riena Example Client):

Revision as of 08:24, 15 January 2010

Riena Controller Testing

Testing your SubModuleControllers is an essential part of assuring the quality of your client. With Rienas Controller Testing support it is quite easy to find problems in your SubModuleController logic at an early stage.

Prerequisites

In order to set up test cases, the SubModuleController has to be prepared to acquire Ridgets without a bound view. To do so the method getRidget(Class<R> ridgetClazz, String id) has to be used in the SubModuleController to test. On the one hand this method wraps getRidget(String id) to return an already known (bound) instance of the Ridget and on the other hand it creates a new instance of the Ridget if run in test mode and no bound widget is existent.

Setting up a test case

All SubModuleControllerTests should extend AbstractSubModuleControllerTest. This class provides the essential operations needed to test a controller. Every test class has to implement the abstract method createController(ISubModuleNode node) where the SubModuleController to test has to be created and returned. Sometimes ist is necessary to set a NavigationNode on the SubModuleController (if things like navigation or marker have to be tested). E.g.:

@Override
protected MarkerSubModuleController createController(ISubModuleNode node) {
  MarkerSubModuleController newInst = new MarkerSubModuleController();
  node.setNodeId(new NavigationNodeId("org.eclipse.riena.example.marker"));
  newInst.setNavigationNode(node);
  return newInst;
}

Testing scenarios

This section coves some in depth examples on how to test your Controllers. More examples are found in org.eclipse.riena.client.controller.test.

Testing Ridget behavior

Here is a short example to test simple correlations between Ridgets (see ChoiceSubModuleController from the Riena Example Client):

public void testPriceAstonMartinWithOptions() {
    ISingleChoiceRidget compositeCarModel = getController().getRidget(ISingleChoiceRidget.class, "compositeCarModel");
    IMultipleChoiceRidget compositeCarExtras = getController().getRidget(IMultipleChoiceRidget.class, "compositeCarExtras");
 
    compositeCarModel.setSelection(CarModels.ASTON_MARTIN);
    compositeCarExtras.setSelection(Arrays.asList(CarOptions.FRONT_GUNS, CarOptions.UNDERWATER));
 
    assertEquals(compositeCarModel.getSelection(), CarModels.ASTON_MARTIN);
    assertEquals(compositeCarExtras.getSelection().size(), 2);
    assertEquals(compositeCarExtras.getSelection().get(0), CarOptions.FRONT_GUNS);
    assertEquals(compositeCarExtras.getSelection().get(1), CarOptions.UNDERWATER);
 
    assertEquals(getController().getCarConfig().getPrice(), 150000);
}

Testing the navigation

Back to the top