SlideShare verwendet Cookies, um die Funktionalität und Leistungsfähigkeit der Webseite zu verbessern und Ihnen relevante Werbung bereitzustellen. Wenn Sie diese Webseite weiter besuchen, erklären Sie sich mit der Verwendung von Cookies auf dieser Seite einverstanden. Lesen Sie bitte unsere Nutzervereinbarung und die Datenschutzrichtlinie.
SlideShare verwendet Cookies, um die Funktionalität und Leistungsfähigkeit der Webseite zu verbessern und Ihnen relevante Werbung bereitzustellen. Wenn Sie diese Webseite weiter besuchen, erklären Sie sich mit der Verwendung von Cookies auf dieser Seite einverstanden. Lesen Sie bitte unsere unsere Datenschutzrichtlinie und die Nutzervereinbarung.
solve problems outside of its domain.2 other modules can be Sample test code using the FEST API optionally used and //Fill in parameters FEST Framework are not described in window.textBox(“firstNumberInput”).enterText(“22”); Open Source Library for GUI Testing this article. window.textBox(“secondNumberInput”).enterText(“2”); • Supports functional Swing GUI test- (See Figure 1) ing //Select action • Website: http://fest.easytesting.org The Swing module is window.radioButton(“sumRadioButton”).check(); • Its API provides a fluent interface divided into different //Calculate • Open Source project (Apache 2.0 layers. “Basic ro- window.button(“calculateButton”).click(); license) bot” is the basic layer of the FEST-Swing //Validate the result • Supports both TestNG and JUnit window.textBox(“resultOutput”).requireText(“24”); module. The class • Simplifies troubleshooting GUI test java.awt.Robot , 6 failures finders that can be used. which is part of the Java Development Kit • Hosted at CodeHaus (JDK), is the main component of FEST-Swing. window.robot.finder(). This class is used to generate native system in- findByLabel(label, type)FEST is a Java-based framework for automated put events for the applications, for which inputfunctional GUI testing, which provides a flu- through the mouse and keyboard is needed. This finder will find a component by its refer-ent interface. FEST is an acronym and stands FEST has created an abstraction interface and enced label.for “Fixtures for Easy Software Testing”. Test the implementation delegates the calls to thecases are implemented as unit tests, and ap- After selecting a component, it is possible to robot class of the JDK.plications based on Swing and SwingFX can interact with this component. As shown in thebe tested. This framework is further developed The “component driver” layer contains example, the input of keyboards can be simu-actively and the javadoc coverage of the source driver classes for all Swing GUI components. lated, just as mouse click events can be sent tocode is high. It has an active community; ques- The driver knows in detail which types of in- the components.tions on the mailing list are answered very fast teraction are possible and how the state can beand efficiently. The existing wiki pages also checked. The JTextFieldDriver inter- The components used in the example are onlyinform about advanced topics. Based on the face, for example, contains methods like: simple GUI components. However, how easyfluent interface offered and the good javadoc is the selection of a special node of a JTree?descriptions, intuitive learning is possible. • enterText(..) Imagine a folder structure that is displayed in a tree:FEST is divided into four modules: • setText(…) • My Documents• Swing • requireText(…) ◦◦ FEST Simulation of user-generated events and • requireEditable(…) solid GUI component lookup ▪▪ Article The component “fixture layer” is located• Assertion3 on top of the driver layer and provides a DSL- ▪▪ Sample oriented API for the tester. The main differ- Flexible and fluent assertions ence between the driver and fixture layers is ◦◦ FitNesse the different style of programming. The driver The leaf node “Sample” can be selected using• Reflection4 layer is designed in a classic object-oriented the JTreeFixture: ‘Fluent interface’ for simplifying usage way and is used by the fixture layer. The fix- of reflection. ture layer is designed in a completely different JTreeFixture myDocument- way: every method returns the GUI compo- sTree = JTreeFixture(Robot,• Mock 5 nent fixture class itself to provide the ability of “folderTree”); Eliminates code duplication and clearly method chaining. This fluent interface makes myDocumentsTree. separates mock expectations from code the API much easier to write and read. selectPath(“My Documents/ to test, improving code readability FEST/Sample”); This small example enters a text into two textThe most important module for automated fields, selects a radio button and clicks on thefunctional testing is the Swing module. The calculation button. The last step is the valida- Another more complex GUI component is a JTable, which differentiates between the rendering and FEST Framework the editing of cells, e.g. a cell displays only a text, but when Swing Assertion Reflection Mock you double-click on the cell, a Component Fixture drop-down list is displayed. The following Java code Component Driver shows an interaction with the To-Do-List table of the demo Basic Robot application: These short examples dem- onstrate the elegance andFigure 1: Overview of the modules of the FEST framework the possibilities of the FEST tion of the calculation. Isn’t this code easy to framework testing Swing applications – the2 http://www.infoq.com/articles/internal- read and understand? new rich internet application technologydsls-java3 http://docs.codehaus.org/display/FEST/ By default, all GUI components can be identi- SwingFX is also testable. For readers who areFEST-Assert fied by name, as in the example, or by type. interested in more examples, a good starting4 http://docs.codehaus.org/display/FEST/ point is the sample application of this article However, there are also more sophisticatedFEST-Reflect with more FEST samples7.5 http://docs.codehaus.org/display/FEST/ 6 http://java.sun.com/javase/6/docs/FEST-Mocks api/java/awt/Robot.html 7 http://github.com/DominikDary/ToDo-www.testingexperience.com The Magazine for Professional Testers 83
Figure 2: Screenshot of the sample application //import static org.fest.swing.data.TableCell.row; Biography Dominik Dary is a Software Engineer //Find table GUI component working for Capgemini sd&m AG in JTableFixture taskTable = window. Germany. Dominik has 5 years practical table(“toDoListTable”); experience in specification and realiza- tion of object-oriented software in Java //Selecting the finish cell / Spring / JEE as well as in quality as- JTableCellFixture finishedCell = taskTable. surance and in business intelligence. In cell(row(0).column(2)); 2005 he wrote his diploma thesis about “Quality Assurance in JEE Projects by // Selecting the checkbox Test-Driven Development”. The practi- finishedCell.enterValue(“true”); cal part of this thesis is based on the finishedCell.background().requireEqualTo(Color. “Cactus” and the “Canoo webtest” GREEN); frameworks. //Selecting the project cell Dominik’s first contact with FEST was in JTableCellFixture projectCell = taskTable. 2008 developing a Java Swing document cell(row(0).column(3)); management / workflow application. His further activities in this project included // Select a value in the comboBox test specification and organization of projectCell.enterValue(“Spring DM”); acceptance tests. // Assert the selected value is displayed afterwards In his current project, Dominik works projectCell.requireValue(“Spring DM”); for an e-commerce company doing test management, performance testing and automated testing with the selenium FEST tests are written as unit tests; both popular frameworks - JUnit and TestNG framework. – are supported. If TestNG is used as unit test framework, this offers the possibil- ity to create your own reports. During testing the application, screenshots can be taken using the ScreenshotTaker manually or automatically if the test fails. Those functional tests can be integrated8 into continuous integration environments like Hudson9 or TeamCity10. For self-developed GUI components, it is helpful to create driver and fixture classes as they exist for the Swing components. Another helpful approach is to create fix- ture classes for GUI dialogs to offer methods for easy component selection and some simple flows, e.g. choosing a file with JFileChooser which can be centralized. This helps to minimize code duplication, simplifies the tests and increases once more the readability of the tests. Newly designed and developed Swing desktop applications are much easier to test if code conventions contain a naming concept to guarantee that each GUI component has a unique name. Tests of complex desktop applications need a flexible, well-documented framework to create maintainable tests; check out the sample application and get started writ- ing functional tests with FEST! List 8 http://docs.codehaus.org/display/FEST/Continuous+Integration 9 https://hudson.dev.java.net/ 10 http://www.jetbrains.com/teamcity/ 84 The Magazine for Professional Testers www.testingexperience.com