Does my test script smell?
-
Upload
martingijsen -
Category
Documents
-
view
1.220 -
download
3
description
Transcript of Does my test script smell?
![Page 1: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/1.jpg)
Does my test script smell?
Detect, fix and preventcommon maintenance issues
with automated tests
Martin GijsenTest automation architect
TESTWAREZ 2009© 2009
![Page 2: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/2.jpg)
Overview● Maintenance of automated tests● Test script smell● Common maintenance issues● Conclusion● Q & A
![Page 3: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/3.jpg)
Automated testing in practice
About 2/3 of all test automation projects fail sooner or later– Brian LeSuer(testing experience magazine,December 2008, page 47)
2
1
time
total cost / effort
1. manual testing2. effective automated testing3. less effective automated testing
3
![Page 4: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/4.jpg)
Maintenance of automated tests● The Record & Playback approach does not work● Total maintenance depends on:
● Number of changes● Maintenance sensitivity (does change affect test?)● Maintainability (how much effort)
● For continuity of benefits, focus on:● 3 R's: Tests must be easy to write, review and revise● Maintainability and maintenance sensitivity
![Page 5: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/5.jpg)
Test script smell (1)● Test script smell is derived from 'code smell'● Wikipedia:
● In computer programming, code smell is any symptom in the source code of a program that possibly indicates a deeper problem.
● Code refactoring is the process of changing a computer program's internal structure without modifying its external functional behavior or existing functionality.
![Page 6: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/6.jpg)
Test script smell (2)● Test script smell is any symptom in an
automated test that possibly indicates a deeper problem.
● Test refactoring is the process of changing the internal structure of an automated test without modifying its external functionality.
● Most test script issues increase maintenance● Focus on the average tester!
![Page 7: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/7.jpg)
Common maintenance issues● Unreadable tests● Long test cases● Repeating sequences● Interface details in test cases● Tooling details in test cases● Literal constants in test cases
Examples will use the freeware ETA Framework
![Page 8: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/8.jpg)
A Selenium test (Java)Selenium selenium = new DefaultSelenium (“localhost”, 4444, “*firefox”, “http://www.google.com”);
selenium.start ();
selenium.open (“/”);
if (selenium.getTitle ().indexOf (“Google”) < 0) {
reportError (“an error message”);
}
selenium.type (“q”, “the quick brown fox jumps over the lazy dog”);
selenium.click (“btnG”);
if (selenium.getTitle ().indexOf (“the quick brown fox jumps over the lazy dog”) < 0) {
reportError (“an error message”);
}
selenium.click (“link=YouTube”);
![Page 9: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/9.jpg)
A keyword based testnew DefaultSelenium localhost 4444 *firefox http://www.google.com
start
open /
getTitle ().indexOf (“Google”)
type q the quick brown fox jumps over the lazy dog
click btnG
getTitle ().indexOf (“the quick brown fox jumps over the lazy dog”)
click link=YouTube
!
![Page 10: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/10.jpg)
Interface details removednew DefaultSelenium localhost 4444 *firefox http://www.google.com
start
open /
getTitle ().indexOf (“Google”)
type ?queryField the quick brown fox jumps over the lazy dog
click ?searchButton
getTitle ().indexOf (“the quick brown fox jumps over the lazy dog”)
click link=YouTube
!
![Page 11: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/11.jpg)
Tooling details removedtype URL
open browser firefox www.google.com
open /
check page title Google
type ?queryField the quick brown fox jumps over the lazy dog
click ?searchButton
check page title the quick brown fox jumps over the lazy dog
select link YouTube
!
!
!
![Page 12: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/12.jpg)
Abstraction level increasedtype URL
open browser firefox www.google.com
web page titleopen page / Google
search stringsearch the quick brown fox jumps over the lazy dog
link textselect result YouTube
![Page 13: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/13.jpg)
The automated test
Test caseTest case
Scripted proceduresScripted procedures
Source codeSource code
Test analyst
Test analyst / Developer
Developer
ApplicationApplication
![Page 14: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/14.jpg)
Conclusion● Abstraction is the key to low maintenance● For easy maintenance:
● Make tests readable (to your manager?)● Make tests compact (high abstraction level)● Remove interface + tooling details (implicit or config)● Use symbolic constants
● Define test instructions top down● Test automation is software engineering● Example test engines: ETA Framework & FIT
![Page 15: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/15.jpg)
Q & A
?
![Page 16: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/16.jpg)
Main sheet & configuration sheetname
run sheet configurationrun sheet procedures
type URLopen browser firefox www.google.com
namerun sheet test cases
Main sheet:
Config sheet: name valuedefine constant queryField qdefine constant searchButton btnG
![Page 17: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/17.jpg)
Proceduresname Param 1 Param 2
define procedure open page url pageTitle
url
open URL ?url
title
check page title ?pageTitle
end procedure
![Page 18: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/18.jpg)
Proceduresname Param 1
define procedure search searchString
input field value
type ?queryField ?searchString
item name
click ?searchButton
title
check page title ?searchString
end procedure
Configuration sheet
![Page 19: Does my test script smell?](https://reader036.fdocuments.in/reader036/viewer/2022072921/5462ed81b1af9f92238b51f7/html5/thumbnails/19.jpg)
The test (case)identification description
begin test case google1 A Google test
web page titleopen page / Google
search stringsearch the quick brown fox jumps over the lazy dog
link textselect result YouTube
end test case
close browser