A general slides for test automation principle, terminologies and implementation
Also, the slides provide an example - PET, which is a platform written by Perl, but not just for Perl. It provides a general framework to use.
2. 2
Outline
â˘Test Automation Principles & Terminologies
ď§ Why Test Automation
ď§ How to do Test Automation
ď§ Terminologies about Test Automation (Sycamore)
â˘Implement the Terminologies in Automation Scripts
ď§ General Conventions
ď§ An Example - PET
4. 4
Top 10 Reasons for Automating Tests - What people said
1. Manual testing sucks.
2. Tool vendor said
âCapture replay works.â
3. Fun to watch the
dialogs popping on the
screen.
4. âAfterwards we can fire
all those pesky
testers.â
5. Everybody else is doing
it.
6. âNo humans were
harmed in the testing of
this software.â
7. Big bucks already spent
on the test tool.
8. Looks good on the
resume.
9. No Testing for Dummies
book ... yet.
10.Keep the intern busy.
5. 5
Reasons for Automating â What people want
⢠Speed up testing
⢠Allow more frequent testing
⢠Reduce manual labor costs
⢠Improve test coverage
⢠Ensure consistency
⢠Simplify testing
⢠Define the testing process
⢠Make testing more interesting and challenging
⢠Develop programming skills
⢠Justify cost of the tools
⢠Of course weâll have automation!
7. 7
Keep it Simple, Sustainable
â˘Uniform/Common infrastructure
â˘Appropriate tools
â˘Manage source code, test data, tools
â˘Agreed Conventions within the team
â˘High-quality Scripts
â˘Gradual Test Automation
8. 8
Quality of Automation Scripts
â˘Maintainability
ď§ Will the tests still run after product design changes?
ď§ Will tests for 1.0 work with 2.0? And can be easily updated?
â˘Reviewability
ď§ Can others review and understand what is being covered?
ď§ Are the scripts documented?, can we make sure it matches the original design?
ď§ How about the coverage? How easy another engineer use the scripts for the next
release?
â˘Reusability
ď§ To what degree the assets can be reused to create more, different tests?
ď§ Can they be reused in different releases, in different environments?
â˘Dependability
ď§ Integrity
ď§ Reliability
â˘Repeatability
â˘Independence
â˘Performance
â˘Simplicity
10. 10
Architecture for Automation
Test Planning Test Preparation Test PerfectingTest Performing
Test Suite
Logical TestBed
Test Case
Test Case
âŚ
Test Case
Test Suite
âŚ
Physical TestBed
Test Case
Test Case
âŚ
Test Case
Test Case
Logical TestBed
Test Case
Test Case
âŚ
Test Case
Test Case
Test Plan
âŚ
Test Step 1
Test Step 2
âŚ
Test Step n
Test Task
âŚ
âŚ
Test Report
Specify TestBed & TestCase List
For a release
Set a task to run a plan
Schedule
Runtime Options+
Schedule
Runtime Options+
Detailed Runtime Information
Detailed TestBed Information
Test Case Result
Test Case Result
âŚ
Test Case Result
Detailed Runtime Information
Detailed TestBed Information
Test Case Result
Test Case Result
âŚ
Test Case Result
Revised
Test Suites
Test Plans
Logical TestBed
Test Case
Test Case
âŚ
Test Case
Physical TestBed
Test Case
Test Case
âŚ
Test Case
Execute a task
11. 11
Test Bed
â˘Briefly, a test bed is the definition of the environment for a
specified test. A test bed include the hardware/software
and configuration/provisioning.
â˘There are two kinds of test beds:
ď§ Logical TestBed. A logical test bed depicts all the elements and
configuration required for the test, but not indicate which exactly
elements will be used (i.e. the index or addresses are not required.)
ď§ Physical TestBed. A physical test bed is an instantiation of a logical
test bed. A physical test bed exactly indicates which elements are
used in the test, and a test task can be really run on the test bed.
⢠Base State of a test bed
ď§ The initial state of the test bed, ready for test case (group) start to
run with it.
ď§ A self-cleaning test case (group) should get the test bed back to the
base state when the execution completed.
12. 12
Test Case (group)
â˘A test case is a sequence of operations against a system
whose results can be used to determine if a requirement
or use case upon an application of the system is partially
or fully satisfied.
ď§ A test case contains a set of test steps, and based on a particular
test bed.
ď§ A test step is an atomic statement of a test case, can have pass/fail
result. Usually it contains one operation and the expected result.
ď§ A set of test cases can be grouped in a test case file.
â˘Test Case File (test group):
ď§ A test case file defines one or multiple test cases, which is based on
a clean test bed for running, and do self-cleaning after performing
all the cases one by one.
ď§ A test group are a set of test cases saved in one test case file.
13. 13
Test Suite
â˘A suite of test cases, which share the same test bed to
verify a specified feature in a specified test area. Usually,
there are multiple test cases in one test suite.
â˘In automation scripts, a test suite includes:
ď§ A test suite file: to describe the basic information of this test suite
ď§ A logical test bed: to define the test bed which the test suite is
based on
ď§ One or more test case files: each test case file is self-cleaning, so
that each file can run independently.
â˘Usually, test suite is feature oriented. It can be created
once the feature is introduced, and keep being improved
along the product life, or even product family life.
14. 14
Test Plan
â˘A test plan is an instantiation of a subset of a test suite, in
which a set of test cases selected for a particular test for a
feature in a program; and indicate the physical test bed
for test performing.
ď§ E.g. we have a BLSR_4F_2Node test suite, then we can make a plan
for SN16K R9.0 BLSR 4F 2Node Regression test, targeted run it in
two days.
â˘In automation scripts, a test plan includes:
ď§ Test suite path/name
ď§ The physical test bed, which is an instantiation of the logical test bed
ď§ A test case file list, selected from the test suite
â˘Usually, a test plan is feature and release oriented. For
different releases, one can have different test plan for one
feature. And, a test plan should be defined in the test
preparation stage.
15. 15
Test Task
â˘Test Task is a runtime concept, it defines when and how to
execute a test plan. Once a test task is executed, a test
report should be reproduced
â˘In automation scripts, a test task could be a command in
CLI, an item in TMS, or a file, which includes:
ď§ The test plan path/name
ď§ A schedule for the test plan running
ď§ Runtime options, e.g. Halt or skip if any failure? Wait or fail if the
test bed is not available? Recycle or one-time running?
â˘Multiple test tasks can be created for a test plan, that
means, a test plan can be executed multiple times in a
release.
â˘Usually, a test task is created in test performing stage by
the tester for one-time running, and will not be reused.
16. 16
Test Report
â˘A test report is a result record of a test task.
â˘Test reports can also be organized by test plans or test
suites for broadened view to analyze requirements
satisfaction.
â˘A test report should have the following information
ď§ Runtime information: e.g. who/where/how had run this task with
what options?
ď§ Detailed test bed information: e.g. build no. for each node, serial
numbers of elements, software versions
ď§ Test results for each case and each step.
â˘A test report can be valuable just with a specified test bed
on which the test was running.
17. 17
Outline
â˘Test Automation Principles & Terminologies
ď§ Why Test Automation
ď§ How to do Test Automation
ď§ Terminologies about Test Automation (Sycamore)
â˘Implement the Terminologies in Automation Scripts
ď§ General Conventions
ď§ An Example - PET
18. 18
Classic Reasons for Automation Failure
10. No clear objectives for automation.
9. Minimal or No attention of non GUI automation.
8. Lack of methodology to success of the project.
7. Automation is easy Just record and playback. â
6. Aim for 100% automation.
5. Testing for automation scripts.
4. No clarity of real cost involved in automation.
3. Automation is part time job of testers.
2. Wrong selection of Test cases.
1. Not treating automation as software development.
20. 20
A flexible framework
â˘General framework allows users define format and
language
â˘User defined languages for:
ď§ Test bed
ď§ Test cases
ď§ Test report
ď§ Test task
ď§ Scheduler âŚ.
â˘General format
ď§ XML
ď§ Perl, Python
ď§ Simply BDD language,
ď§ Spreadsheet
22. 22
An example: PET
â˘Pet: Peal Engine for Test
ď§ It is not just for Perl testing, but
ď§ Implement a framework to support different test format
ď§ It is independent to run as an application
ď§ Or, to be used as a library for your bigger framework
â˘Key engine: Test Recorder
â˘Download from: https://github.com/steven004/Pet
24. 24
What is Pet?
â˘Pet â Perl Engine for Test
ď§ Perl: Pet is based on Perl. It can run on almost any platforms
ď§ Engine: It will speed up your work, and provide lots of benefit
ď§ Test: It is designed for test, not just for test execution, but test
management as well
IQstream
WebUI
SN9K/3K/16K
âŚ
Support different products
Console
HTML
TMS
E-Mail
âŚ
TEA XML Perl âŚ
Support different format/language
Support different outputs
Test Plans/Suites
Pet Engine
Library
Key-Words
Objects
âŚ
Test Cases
Test Beds
TestRecorder
25. 25
Why you need Pet?
â˘TestRecorder Module embedded in Pet
ď§ You will get test results via different channels
ď§ Console output, HTML files for Web, E-mail notification, TMS database, and more if you request
ď§ All the channels can be configured, you can select any of them as you like/need when running your scripts.
ď§ A bunch of test recorder functions provided
â˘Multi-format supported for scripts writing
ď§ Pure-perl
ď§ TEA format compliant
ď§ Or mix-programming
ď§ You can use Perl in your TEA case file; or use TEA format in Perl scripts
ď§ Spreadsheet cases
⢠Scripts running control
ď§ A mechanism provided to run scripts case by case, or step by step
ď§ Runtime control provided, by âCtrl-câ
ď§ Failure handling, for collect information in your scripts.
ď§ Error handling, If there is some syntax problem in your scripts, Pet
will let you know.
26. 26
How to run Pet â the 1st
step
⢠Pet looks complicated, but we make it simple
⢠Letâs start
a. Log into an automation Server using your unix account
⢠172.21.7.200 (Shanghai) or 172.31.115.6 (Chicago)
⢠Run Pet
-bash-3.2$ pet
/usr/bin/pet requires arguments. Try âpet âhâ for help.
-bash-3.2$ pet -h
Usage: Pet [-cnhpv] [testplanfile] [switches] [arguments]
-u UserName indicate the who is running the test scripts. Pet will get the user name from OS if no this option
-h print Usage hints
-l OutputDir indicate the output directory of log. tmppetusername will be used for the default output directory
-m the mail address for test result reports
-v print version, subversion <includes VERY IMPORTANT Pet functionality info>
-d [:debugger] run program under debugger (future)
-b BuildNumber indicate the build number of the system/software under test
-n new a test plan file in current directory based on the existing test bed and test case files
-p parse the test plan and print the case list to the standard output
-r ReleaseName indicate the release name/number of the system/software under test
-o [tms/console/html/xml/txt] indicate the environment of the Pet. Local run by default
-c Pet will just check test bed availability, instead running all cases in the test case list
-t TaskID indicate the test task ID for TMS. This option is just required by TMS to run the Pet
-f
[KEEP_RUNNING/STOP_ON_STEP_FAIL/STOP_ON_CASE_FAIL/PROMPT_ON_FAIL/PROMPT_BY_STEP/PROMPT_BY_CASE/T
EST_QUIT] continue the program or stop it when there is a case fail
27. 27
Pet running examples
â˘Run a Perl file
ď§ $ pet example.pl âr 1.0
â˘Run a Perl-format test plan
ď§ $ pet example_pl.xml âr 1.2 âb B2.8
â˘Run a Tea-format test plan
ď§ $ pet example_tea.xml âr 1.2 âb B2.7 âm steven004@gmail.com
â˘More parameters
ď§ $ pet example_tea.xml âr 1.2 âb B2.7 âu xli âm
steven004@gmail.com ât 53432 âo CONSOLE â l /tmp/xli
â˘Parse TestPlan
ď§ $pet âp exampletp.xml
28. 28
Outline
â˘Pet Basic
â˘Quick Start
ď§ Understand test plan, test suite, test bed and test suite
ď§ Create your own test task
ď§ Testbed modification
ď§ Testcase files selection
ď§ Where you get the results?
ď§ Email, HTML, TMS?
â˘I want to do some change
â˘Advanced: How can I use Pet to write scripts
â˘Dig into Pet
29. 29
Terms â Test Plan/Bed/Suite/Task/Report
â˘See details in
ď§ Previous slides
â˘Pet is to run a test plan in which
ď§ Test Bed, Test Suite, Test Case list are specified
â˘A test plan example
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Test Engineer: Guo, Hugh -->
<!-- Program: Pet Example -->
<!-- Description: Tea-type example test plan -->
<TestPlan
SuiteFile="../exampleSuite.pl"
PhysicalTestBedFile="../PhysicalTestBeds/example_tb.ttb">
<TestCases>
<File>../TestCases/example_tc.ttc</File>
</TestCases>
</TestPlan>
ďź Use Relative paths in your test plan, instead of absolute ones ďź
30. 30
Create your own test task
â˘Create/Modify TestBed file
â˘Create/Modify test plan file
ď§ Indicate the test suite file
ď§ Indicate the test bed file
ď§ TestCase files selection
ď§ Again, Use the relative paths, instead of absolute ones
â˘Demo âŚ
31. 31
Where is my test results?
â˘Important Environment Variables
ď§ Get it by running âsetâ in Linux
-bash-3.2$ set
âŚ
TESTMAILTO=steven004@gmail.com #results will be sent to this mail.
TESTRECOPT='TESTSUMMARY|TESTDETAIL|TESTLOG|ERRORLOG|WARNINGLOG|INFOLOG|DEBUGLOGâ
# All logs will be recorded
TESTRECPATH=/shared1/users/IQstream_Result/auto_pet/output/
#The place to save output results
TESTRECTO='CONSOLE|HTML|EMAILâ #You can get results through Console, Email and HTML files.
âŚ
â˘DemoâŚ
32. 32
Outline
â˘Pet Basic
â˘Quick Start
â˘I want to do some change
ď§ Use default output options
ď§ Set Pet Environment Variables
ď§ TESTRECOPT, TESTRECPATH, TESTRECTO, TESTMAILTO
ď§ Set Pet Options in your scripts
â˘Advanced: How can I use Pet to write scripts
â˘Dig into Pet
33. 33
All about TestRecorder
â˘TestRecorder Manual
ď§ https://github.com/steven004/Pet/blob/master/Documents/TestReco
rder.htm
â˘TestRecorder Training Slides
ď§ https://github.com/steven004/Pet/blob/master/Documents/Use
%20PET%20step%20by%20step.ppt
â˘Default TestRecorder Options had been set in automation
servers for all users
ď§ For TestRECTO, TESTRECPATH, TESTRECOPT
â˘You need to set TESTMAILTO
â˘You can also set your own Recorder Options in your profile
34. 34
Use different options for a particular test
â˘Two ways to go
ď§ 1) Specify your options as arguments when you run your test
ď§ pet myplan.xml âm notme@abc.com âr 1.2 âb 1 âl /tmp/xli/
ď§ This time, notme@abc.com will get the result, and all results
files will be save in /tmp/xli in the automation server
ď§ pet myplan.xml âu goldman âr 1.2 âb 3.8 âf STOP_ON_CASE_FAIL
ď§ This time, pet will think the goldman is running the scripts, instead of
you, the one log into the server, and scripts will stop once there is a
case fail.
ď§ 2) Set in your scripts (not recommended)
ď§ See more in TestRecorder Training Slides
35. 35
Outline
â˘Pet Basic
â˘Quick Start
â˘I want to do some change
â˘Advanced: How can I use Pet to write scripts
ď§ Call Flow in Pet
ď§ TestSuite file writing
ď§ TestBed & TestCase file
ď§ Pure Perl programming
ď§ TEA format programming
ď§ Mix-mode programming
â˘Dig into Pet
36. 36
Call Flow in Pet
â˘Typical call flow
Import TestSuite
(run testsuite file)
Import TestBed
(run PhyTestBed file)
TestBed Setup
Test Start
Test End
TestBed Cleanup
Run CaseFiles #1
#2
âŚ
#n
Case, Step & TestLog
related functions (defined
in TestRecorder) can be
used here, and all activities
will be recorded by Pet.
37. 37
TestSuite file
â˘TestSuite file has to be a Perl file
â˘It could be very simple
â˘The simplest example:
# A Test Suite Example
use IQsteam::Objects; # it means you will test a IQstream system
â˘The TestSuite.pl template:
## use the necessary packages here
use IQsteam::Objects;
sub TestBedSetup {
#add your scripts here#
1;
}
sub TestBedClearup {
#add your scripts here#
1;
}
1;
38. 38
TestSuite file is serving the test suite
â˘Anything related to the test suite should be defined in it
â˘It may contain
ď§ The packages to be used in the test suite
ď§ The attributes of the test suite
ď§ Test Bed base state definition (TestBed Setup)
ď§ How to recover the test bed after test completes
ď§ Any variables/data to be used in the test suite, but not related to a
particular physical test bed
ď§ Any functions definition for test cases & Test bed initiation
ď§ E.g. the testsuite.pl defined for Lab Pcap running
39. 39
TestBed & Test Case files
â˘Test Bed design
ď§ Define variables/data related to particular test beds, i.e. Any
parameters may change when you change your test bed to do the
same test
â˘Test Case file design
ď§ Test Case file is just to define test procedures
ď§ Test Case files should not be modified when you run your test on
different test beds
ď§ Case / Step / TestLog related functions defined in TestRecorder will
be used in TestCase Files
ď§ Test Cases defined in one TestCase file should be self-clean for
better test plan making
40. 40
TestBed & TestCase Files â Pure Perl
â˘TestBed Example (from WebUI test suite)
our $BrowserType='*iexplore';
our $BrowserURL='http://172.21.5.109';
our $CNIPAddress='172.21.5.109';
our $client_IP='172.21.160.154';
our $PortNumber='4444';
ď§ All the definitions are about the particular test bed, and can be easily
changed when you run it in another test bed.
â˘TestSuite Example
CaseStart(âJust an example");
{
InfoMsg(âAll the following steps should pass!");
Step(3*2==6, "3*2==6");
Like(âShanghaiâ, âShâ, âShanghai =~ Sh");
Is(3*2, 6, "3*2 is 6?");
} CaseEnd();
âŚâŚ
CaseStart(âOther CasesâŚ.â); {âŚ} CaseEnd();
More Functions, please
see TestRecorder Manual
Editor's Notes
Actually, Pet is not a good name, since it is really like a robot or a dog, instead of a pet, which need you to take care of. On the contrast, it provide much more benefit to you, and help you