4.3.5. Design for testability in RCP

4.3.5.1. Naming components

Although components can be located in the AUT even when they are not named by the developers, naming components is nevertheless a good idea. In SWT and RCP there is no method like the Swing setName method to name components in the program code. However, you can improve the testability of your application by using the following method in your SWT or RCP code for the current component class: setData(String key, String ComponentName). For the key, use TEST_COMP_NAME.

Even if you do not name components, you can choose to have unique names generated for your components in the AUT in the AUT dialog (Section 3.7, “Defining applications under test (AUTs)”).

4.3.5.2. Adding support for text retrieval

You can add support for renderers for SWT components or items without the getText() method in order to access text that is otherwise non-readable during test execution.

Use the method setData(String key, Object value) on the instance of the component or item whose text you want to access. The key is TEST_TESTABLE_TEXT

For example, to access an otherwise unreachable text on a label:

myLabel.setData("TEST_TESTABLE_TEXT", label);

If you are making text in e.g. a table accessible, then you will need to add a dynamic part for the column, e.g.:

myTableItemInstance.setData
("TEST_TESTABLE_TEXT_" + colIdx, text);


Copyright BREDEX GmbH 2015. Made available under the Eclipse Public License v1.0.