How to have language-independent UI tests with SWTBot and NLS
To make sure you have UI tests that will evolve seamlessly with UI naming modification, use the Internationalized String and not the hardcoded value of text displayed in the UI. Even if hardcoding seems simpler at test writing time!
Each plugin needs to export the package containing the NLS class to use it in the test plugin. To avoid polluting the completion of your IDE, and making some classes visible at runtime that you don't want, follow these three points:
- Isolate your NLS class
- Use x-friends directive
- Use Internationalized String
Let’s explain these points!
Isolate your NLS class
Isolate the class responsible for translation in a specific package. At Bonitasoft, we call this package i18n.
It will export only classes which are related to translation.
Use x-friends directive
Open the MANIFEST.MF with the PDE editor. Then export the i18n package and specify the Package Visibility to your test plugin:
If you look at the textual content of MANIFEST.MF, you will notice that an x-friends directive has been added:
Use Internationalized String
Finally, in your test code write something like:
- import org.bonitasoft.actors.i18n.Messages;
This good practice will improve the robustness of your test and save a lot of time.