В докладе рассказано о нескольких подходах к автоматизации тестирования через пользовательский интерфейс. Вы узнаете как автоматизировать приложения на Java Swing. Также будет рассмотрен инструмент автоматизированного тестирования Jemmy, продемонстрирована работа с ним. Еще вы познакомитесь с новыми возможностями Jemmy 3.
Scaling API-first – The story of a global engineering organization
Automating JFC UI application testing with Jemmy
1. <Insert Picture Here>
Automating JFC UI application testing with Jemmy.
Alexandre (Shura) Iline
Java SE and JavaFX Quality architect.
2. The following is intended to outline our general product
direction. It is intended for information purposes, and
may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or
functionality, and should not be relied upon in making
purchasing decisions.
The development, release, and timing of any features
or functionality described for Oracle's products remains
at the sole discretion of Oracle.
4. What's in scope
• All sorts of definitions
“Testing”, “UI testing”, “Test automation”
• Jemmy library
• Automation approaches effectiveness and cost.
• Bunch of source code
• Basic Jemmy operations
• Less basic operations
• Switches and settings
• Tricks and tips
• Misconceptions
5. What's not in scope
• The economical effects
• A.k.a. what's “quality”
• Why to automate
• Automation cost vs. manual testing cost
• When to automate
• What to automate
• Non-economical benefits of automation
A.k.a. let's leave it for later. :)
6. UI testing … by Wikipedia
«GUI software testing is the
process of testing a product
that uses a graphical user
interface, to ensure it meets its
written specifications.»
7. UI testing … most often ...
«Checking whether usage of a
product UI leads to results
expected by the the person
who performs testing»
8. Sample test scenario
●Start text editor
●Push «File/Open»
●Verify file chooser directory
●Select some file
●Verify editor area content
●Verify application title
●Verify buttons availabilities
●
....
9. UI test workflow
Pass
Perform necessary
actions
Find Pass Do Pass Verify
Find next control Verify that expected
To perform operation State reached
Fail Fail Fail
Failure analysis
10. Test automation ... for me
«Building a process which
exercises and reports certain
product characteristics while
run unattended.»
11. Test automation is like development
• Putting logic in a code
• Same lifecycle:
• Requirements
• Design
• Implementation
• Same set of problems
• Bugs
• Instabilities
• Scope
• defined through test specification/plan
12. Test automation is not like
development
• Big fat dependency – the tested product
• vs many libraries and platform
• Many small programs
• vs one big program
• Does one thing good – reports status
• vs does many thing ... good
• Perfectness is not the goal
• other than maintenance cost, ease of use
14. Jemmy history
• Started as a tool to tests TeamWare UI (1999)
• Used for NetBeans extensions (2000)
• Official test tool for NetBeans (2001)
• Open-source (2001)
• Is used for NetBeans and extensions since then
• Adopted as a test tool for Swing (~2003)
• Used outside SUN Microsystems (next slide)
• Jemmy v3 created (2008)
• The test tool for JavaFX SDK (2008 – now)
• Extended to support SWT
• Test tool for JRMC
17. Same VM.
Test code runs in the same VM as the application code
• Benefits
• Full access to the application UI objects
• As well as the application domain object (sometimes).
• Control over event queue
• Drawbacks
• Impacts the tested UI
• Options
• Run application from test
• Run test from application
• Use accessibility hook
28. Dispatching modes
• Events
• Proper events in a proper order are dispatched to a
component making it thinking some user actions are
performed.
• Shortcut
• Same as events except the events are posted into the event
queue at once.
• Robot
• java.awt.Robot is used
Implemented with driver sets
34. Coordinates
• click(134,32) //selects some record
• click(215,122) //hits “Properties”
• sleep(5) //sleeps to let dialog be painted
• click(64,182) //expands color combo
• click(235,182) //selects Gray
• click(235,212) //hit OK
34
34
36. Widgets or coordinates
Car record
Domain
Domain
model
model
Model
Model Make VIN
VIN Color Year License plate
Make Color Year License plate
Product UI
Product UI
Test
36
36
38. UI Primitives
• Find car list frame
CarListFrame list = new CarListFrame()
• Open properties dialog for car “1abc234”
CarDialog propDialog =
list.carProperties(“1abc234”);
• Set color to gray
propDialog.setColor(Color.GRAY);
• Apply changes
propDialog.ok();
38
38
39. Library
Domain
Car record
Domain
Model Make VIN Color Year License plate
model
Model Make VIN Color Year License plate
model
Product UI
Product UI
CarListFrame Test library
Test library CarDialog
Test
39
39
41. Domain model
• Set color to gray for a car “1abc234”
new CarRecord(“1abc234”).
setColor(Color.GRAY);
Underneath the cover, CarRecord class does
all described earlier
41
41
42. Domain library
Domain
Car record
Domain
model
Model Make VIN Color Year License plate
model
Model Make VIN Color Year License plate
Product
Product
UI
UI
CarList UI test library
UI test library CarDialog
CarRecord Domain test library
Domain test library
Test
42
42
45. The formula?
TM * NR * NC
EA =
TD + TS * NR * NC
EA – automation effectiveness
To be used for every particular product.
NR and NC are unique for a product.
TM is a characteristic of a test suite.
Smaller TD and TS - higher the EA.
Coefficient depend on the way you write your tests
48. EA for NC=3, NR=8
3.5
3.24
3
2.76
2.5
2
1.6
1.5
0.96
1
0.5
0
Coordinates Widgets UI Library Domain library
Ea
49. Misconceptions
• Automated testing replaces manual testing
• it will find all the bugs
• it will find more bugs
• it does the same amount of work
• Create once use forever
• This is easy
• This is too hard
• No need to create test plan
• “Will just buy the XXX tool and it will solve all out
problems”
51. <Insert Picture Here>
Automating JFC UI application testing.
With Jemmy.
The technical aspects.
Alexandre (Shura) Iline
Java SE and JavaFX Quality architect.
53. Coverage
• Implementation coverage
• Line, block, condition, sequence, ...
• Specification coverage
• How well the tests covering the functional specification
• Public API coverage
• Whether the public API is tested fully
• UI coverage
• Whether the tests cover UI fully
• Combine with bug density
• First cover the areas with more bugs
• Combine with code complexity
• First cover the more complicated code.
54. Continuous build
Build
Executed
Code automatically Success
Commit
changes after commit
Yes.
No
Analysis.
Rollback!!!
Development
Promote
Test further Code is compilable
55. Continuous build with testing
Code Build Success
changes Commit
No
Rollback!!! Yes.
= Compilation
Test Analysis. successful
changes No
Testing
Test further Passed
Build is good Yes Is it working?
Code line is healthy
Go on ...
57. How to benefit from UI automation?
Use it!
• Sanity
• Pre-integration
• Attach to bug reports
• Make is a quality criteria
• Run it for every build
• Show it to the boss :)
• Don't forget to show it to the dev. team
Editor's Notes
This is to let you know that I know what I am talking about All I am going to say is based on experience I've gotten from testing different UI products talk some of which I was either a lead of or participated or been in a contect with people doing the testing because my technology was used
They say there should be a spec. Lucky you if you have a spec detailed enough to write automated tests.
that's more like it. Testing implementation ...
Just to get on the same page ... This is what I am talking about – functional testing of UI
I do not define test here on purpose otherwise we would drown into it. Quality here defined loosely. More like “conformance to criteria”
I will also be saying that you also need to design it.
big fat dependency – and the version is given Many small programs (one big program) Outcome is just the status (product functionality) no need to be perfect how test veryfies the not too much performance maintanance - yes
Jemmy v2 is really old and very stable. There are no major bugs there. As no new functionality went into JFC for a long time, no new stuff need to be added there either. Such products as NB and JFC are tested with it, to name a few. Jemmy v3 has a totally new design although it is based on the same principles. Main design point is to reuse as much code for different UI libraries as possible. Note that even Jemmy v3 has an AWT/Swing extension, I do recommend everybody to use Jemmy v2. JemmyAWT is only for testing JemmyCore
this requires recording naturally
this could be done manually or through a recording tool
Now would happen if the combobox is replaced by color chooser page up test would fail, 'cause it's looking for combobox page down Most importantly ... all tests would fail!
Obvious solution this kind of code already could not be generated by a recording tool This survives changes within editing dialog
not a unit test not a product classes CarRecord is a test code
as long as there is a car and a color ...
found complicated formulas in the web
did not hear many myself – there plenty described on the web – these I did see joke about buys vs buying
did not hear many myself – there plenty described on the web – these I did see joke about buys vs buying
First of all there very little use to measure only the automated tests coverage Implementation coverage does not have a target value. In order to define what must be covered – need to filter one way or the other.
This is a well accepted practice nowadays. However it is not really possible without testing. And it is not really possible with manual testing as the turnaround is too long to rely on.
This is a well accepted practice nowadays. However it is not really possible without testing. And it is not really possible with manual testing as the turnaround is too long to rely on.