A Java implementation of the GUITester
The techniques used in my .NET GUITester project, though developed using C#, are applicable to any of the 30+ .NET Framework supported languages.
.NET does provide support for Microsoft's own 'Java like' language J#, but this is not actual Java. So I have done a small trial to see if similar techniques i.e. reflection and annotation (as Java terms attributes) could be applied in a 'pure' Sun Microsoft Systems Java 1.5 reference implementation. The aim of this trial was to try to replicate the first tests I did in .NET:
- Discover GUI components in a Swing based application
- Add custom annotation to GUI components
- Cause a button event to be fired and see its result.
The key changes required in the port from C# were:
- Private Members - By default Java reflection does not allow access to private members. This is a major issue for this testing model. It is a key requirement of this project that the developer should not be required to change from 'good software engineering practice' e.g. by making private members public. A solution to this problem was found on OnJava.Com . This allows a backdoor route into the class under test using the getDeclaredField() method.
- Event Triggering - In Java, GUI events are callable methods of the GUI control, so triggering events is actually a simpler task that under .NET when the event model has to be invoked.
To get the source for this trial, as a Java Netbeans 4 project, click here.
Richard