Testing plug-ins has never been considered very sexy... Nor is it very easy to through-roughly test all aspects of a plug-ins. A lot of obvious tests are often omitted for these reasons - even though we all know that a good test suite will save you from trouble time and time again.
In this talk I will illustrate 10 easy techniques to test various aspects of a plug-in, ranging from the simple UI tests and tests of plug-in dependencies, over the tests of property testers, source providers and expressions to tests of dialogs and wizards.
The focus in the presentation will be on practical techniques, that can be used directly in your own plug-ins and applications. The presentation is intended for everybody interested in tests or just forced to test plug-ins and not knowing where to start...
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen
EclipseCon '11 - 10 Techniques to Test a Plug-in
1. 10 Techniques to Test a Plug-in
Testing plug-ins has never been considered very sexy... Nor is it very easy to through-
roughly test all aspects of a plug-ins. A lot of obvious tests are often omitted for these
reasons - even though we all know that a good test suite will save you from trouble
time and time again.
In this talk I will illustrate 10 easy techniques to test various aspects of a plug-in,
ranging from the simple UI tests and tests of plug-in dependencies, over the tests of
property testers, source providers and expressions to tests of dialogs and wizards.
The focus in the presentation will be on practical techniques, that can be used directly
in your own plug-ins and applications. The presentation is intended for everybody
interested in tests or just forced to test plug-ins and not knowing where to start...
Redistribution and other use of this material requires written permission from The RCP Company.
L0001 - 2010-11-27
2. Main Testing Aspects
MANIFEST.MF
User Interface
Everything that connects plugin.xml and Java
Commands and Handlers
Expressions
Source Providers
Views and Editors
Reading the extension registry
...and the functionality provided by the plug-in itself
2
L0001 - 2010-11-27
3. Where to put Tests
Tests of plug-ins can be put several places each with separate pros and cons
Inline in the application plug-ins
Pros: Easy to manage, access to everything
Cons: In the final product, some tests are not possible
In separate plug-ins
Pros: Separate from the product
Cons: Only access to the exported interface
In attached fragments
Pros: Access to everything, separate from the product
Cons: A different “thing” from plug-ins, difficult to test via PDEbuild
3
4. MANIFEST.MF
Test Basic Identity Use OSGi Platform Admin service to
ID, Version number, Singleton find dependencies and status for
bundles
or not, ....
Use OSGi Package Admin service to
Test Dependencies
find exported packages
Version numbers should
normally be ranges Unfortunately, you cannot see
which Java packages are present in
Certain dependencies are not
a bundle, so it is impossible to test
allowed
are all non-internal packages are
Test that the current API is exported
compatible with the old baseline
All relevant fields are localized
Test exported Java packages
Test fragments are enabled on the
correct platforms
4
L0001 - 2010-11-27
5. plugin.xml
Should be well structured XML that Parse the extension point
conforms to the extension points declarations (exsd) and use this to
drive the tests
All Java references must be create-
able and not on the form “plugin/ Can require access to source
class” bundles
All referenced images should exist
All relevant fields are localized
All ID references must point to an
existing declaration
5
L0001 - 2010-11-27
6. User Interfaces
Should test the intended Many different tools available
functionality and interaction of all Use tools like SWTBot,
controls BaseTestUtils
Key focus point Many techniques available
Testing should be independent drive from outside
of current localization
language as well as the exact use Display.post(...)
layout of views, dialogs, change controls directly
wizards, etc
use commands
Can be very tricky at times
Many small differences between
platforms
6
L0001 - 2010-11-27
7. Commands and Handlers
Test the state and functionality of Consider commands as methods
commands and handlers and test them as such!
Test the correct value of any state Use an IExecutionListener to
associated with commands monitor the execution of
commands and handlers
Test the use of any command
parameters Use ICommandListener to test that
the handled and enabled attributes
Test enablement of commands and are changed correctly as a
handlers consequence of changes in the
context
Test the visual appearance changes
made by handlers that inherit from If possible, then create a special
IElementUpdater menu with the commands, where
the handlers can update the visual
appearance
ICommandService.deserialize is
practical when testing commands
and command arguments
7
L0001 - 2010-11-27
8. Views (and Editors)
Can all parts be created Use IWorkbenchPage.showView to
Also with a current selection open views
Remember to hide them again
Test removal of all listeners when as this might otherwise make
the part is disposed later tests fail
For views with allowMultiple, test Use reflection to count number of
that multiple views are in fact listeners in workbench framework
created with the correct content before and after the view has been
(and be re-created when the shown
application restarts)
8
L0001 - 2010-11-27
9. Property Testers
Test that all property testers can be Read information from
loaded propertyTesters extension point
and test all test expressions against
Check used property names in test this
expressions
No errors are shown it you Use
IEvaluationService.addEvaluationList
refer a non-existing property
ener to test the re-evaluation of
name
expressions
If relevant, test that expressions
are re-evaluated when the property
tester changes state
9
L0001 - 2010-11-27
10. Source Providers
Test that all service providers can Read information about the
be properly loaded relevant source providers from the
services extension point
Test that the following all agree
the declared variables via the
extension point
the reported variables from the
provider object
current state as reported by
the provider object
Test that all declared variables have
the correct priority
Test that the variables serviced by a
specific provider does point back to
the provider by the provider service
10
L0001 - 2010-11-27
11. Expressions
Test all expressions are correct Read all expressions from the
relevant extension points
Test that all referenced sources
exists Can be based on the extension
point declarations (exsd) that
Test that all operations/tests on the include expression.exsd
different sources match in type
activePartId is a String
selection is (normally) a
collection
11
L0001 - 2010-11-27
12. Dialogs and Wizards
Special problems with most UI test Use Display.timerExec(..) to execute
approaches - dialogs and wizards your own code in the dialog event
have their own event loop loop
Separate out the code for the finish
part of the wizard is a separate
class
12
L0001 - 2010-11-27
13. Unwanted Messages
Test that all other tests does result Install a ILogListener in
in additional log messages IApplication.start
Test that reading and parsing Replace the exiting PrintStream
plugin.xml does not result in any with a version that fails the tests
log messages
Test for leftover System.out.print
13
L0001 - 2010-11-27
14. Resources
See the blog entries “Testing a Plug-in” on
my blog - http://blog.rcp-company.com$
Planet Eclipse - http://planeteclipse.org/
14
L0001 - 2010-11-27
15. About Me
Tonny Madsen, Founder and Owner of The RCP Company
20 years of experience in system development in major
companies
9 years of experience with Eclipse and Eclipse RCP
Chairman of Eclipse.dk
Extern Lecturer at IT-University on Model Driven Development and
Domain Specific Languages
Regular speaker at EclipseCon, Eclipse Summit Europe, Eclipse
Summit India, etc
Reached via
tonny.madsen@rcp-company.com
Phone: +45 70 22 25 92
Twitter: tonnymadsen
Blog: http://blog.rcp-company.com/
LinkedIn: http://linkedin.com/in/tonnymadsen
15
L0001 - 2010-11-27
Notes de l'éditeur
\n
A high-level talk. The details will be in a number of blog entries. The first two coming tomorrow...\n
\n
Version Numbers: Use of “.qualifier” or “.SNAPSHOT” in version numbers\n
\n
Techniques: events, direct manipulation, driving the UI\n