SlideShare a Scribd company logo
1 of 35
Ivan Marsic
Rutgers University
LECTURE 11: Software Testing
2
Topics
Overview of Software Testing
1. Make a plan for systematic testing
2. Write and run tests; test automation
Designing Tests for High Coverage
Practical Aspects of Unit Testing
Integration and System Testing
Security Testing
Do I Need to Do Testing?
Everyone who develops software does testing—that’s
unavoidable
The only question is whether testing is conducted
haphazardly by random trial-and-error, or
systematically, with a plan
Why it matters? —The goal is to try as many “critical”
input combinations as possible, given the time and
resource constraints
– i.e., to achieve as high coverage of the input space as is
practical, while testing first the “highest-priority” combinations
– Key issue: strategies for identifying the “highest priority” tests
3
Overview of Software Testing
 “Testing shows the presence, not the absence of bugs.” —Edsger
W. Dijkstra
 A fault, also called “defect” or “bug,” is an erroneous hardware or
software element of a system that can cause the system to fail
 Test-Driven Development (TDD)
• Every step in the development process must start with a plan of how to verify that
the result meets a goal
• The developer should not create a software artifact (a system requirement, a UML diagram,
or source code) unless they know how it will be tested
 A test case is a particular choice of input data to be used in testing
a program and the expected output or behavior
 A test is a finite collection of test cases
4
White-box testing exploits structure within the program (assumes program code available)
Black-box testing explores input space of functionality defined by an interface specification
5
Why Testing is Hard
 Any nontrivial system cannot be completely tested
– Example: testing 4-digit numeric keycodes
• You never know with certainty that all 4-digit codes work as expected unless you try all
• But, what happens with “incomplete” (3-digit, 2-digit) codes? Will all of them timeout to reset state?
• Or, will all tuples (pairs, triplets, etc.) of successive incomplete codes timeout to the reset state?
 Our goal is to find faults as cheaply and quickly as possible.
– Ideally, we would design a single “right” test case to expose each fault and run it
 In practice, we have to run many “unsuccessful” test cases that do not
expose any faults
 A key tradeoff of testing:
– testing as many potential cases as possible (high degree of “test coverage”)
while keeping the economic costs limited
 Underlying idea of software testing:
– the correct behavior on “critical” test cases is representative of correct behavior
on untested parts of the state space
6
Logical Organization of Testing
Unit
test
Unit
test
Unit
test
Integration
test
Component
(unit) code
Component
(unit) code
Component
(unit) code
Integrated
modules
Function
test
Quality
test
Acceptance
test
Installation
test
System
test
System
in use
Ensure that each
component works
as specified
Ensures that all
components
work together
Verifies that functional
requirements are
satisfied
Verifies non-
functional
requirements
Customer
verifies all
requirements
Testing in
user
environment
(“platform”)
( Usually not done in a linear step-by-step order and completed when the last step is reached! )
Black box testing
(by customer)
White box testing
(by developer)
7
Acceptance Tests – Safe Home Access Examples
[ Recall Section 2.2: Requirements Engineering ]
 Test with the valid key of a current tenant on his/her
apartment (pass)
 Test with the valid key of a current tenant on someone
else’s apartment (fail)
 Test with an invalid key on any apartment (fail)
 Test with the key of a removed tenant on his/her previous
apartment (fail)
 Test with the valid key of a just-added tenant on his/ her
apartment (pass)
Input data
Expected result
( “black box” testing: focus on the external behavior )
Example: Test Case for Use Case
8
8
Test-case Identifier: TC-1
Use Case Tested: UC-1, main success scenario, and UC-7
Pass/fail Criteria: The test passes if the user enters a key that is contained in the database,
with less than a maximum allowed number of unsuccessful attempts
Input Data: Numeric keycode, door identifier
Test Procedure: Expected Result:
Step 1. Type in an incorrect
keycode and a valid door
identifier
System beeps to indicate failure;
records unsuccessful attempt in the database;
prompts the user to try again
Step 2. Type in the correct
keycode and door identifier
System flashes a green light to indicate success;
records successful access in the database;
disarms the lock device
[ Recall Section 2.3.3: Detailed Use Case Specification ]
Test Coverage
Test coverage measures the degree to which the
specification or code of a software program has
been exercised by tests
– “Big picture”: Specification testing focuses on the
coverage of the input space, without necessarily testing
each part of the software  Acceptance tests
– “Implementation details”: Code coverage measures the
degree to which the elements of the program source
code have been tested  Unit tests
9
Heuristic: Some Tests are
More “Critical” than Others
Test cases should be prioritized—some tests are more
likely to uncover faults
Tests are about finding developer errors, and people are
prone to make certain kind of errors
Some tests can easier pinpoint problems than others
(some) Heuristics for achieving high coverage:
(could be applied individually or in combination)
– equivalence testing
– boundary testing
– control-flow testing
– state-based testing
10
mostly for “black-box” testing
mostly for “white-box” testing
11
Input Space Coverage:
Equivalence Testing
 Equivalence testing is a black-box testing method that divides
the space of all possible inputs into equivalence groups such that
the program is expected to “behave the same” on each input
from the same group
• Assumption: A well-intentioned developer may have made mistakes that affect a whole
class of input values
• Assumption: We do not have any reason to believe that the developer intentionally
programmed special behavior for any input combinations that belong to a single class of
input values
 Two steps:
1. partitioning the values of input parameters into equivalence groups
2. choosing the test input values from each group
Equivalence classes:
0 100
valid equivalence class
invalid equivalence classes
0 100
valid equivalence class
invalid equivalence classes
12
Heuristics for
Finding Equivalence Classes
 For an input parameter specified over a range of values, e.g., a
number or a letter, partition the value space into one valid and
two invalid equivalence classes
 For an input parameter specified with a single value, e.g., a
unique “security code,” partition the value space into one valid
and two invalid equivalence classes
 For an input parameter specified with a set of values, e.g., day
or month names, partition the value space into one valid and
one invalid equivalence class
 For an input parameter specified as a Boolean value, partition
the value space into one valid and one invalid equivalence
class
13
Input Space Coverage:
Boundary Testing
Boundary testing is a special case of equivalence
testing that focuses on the boundary values of
input parameters
– Based on the assumption that developers often
overlook special cases at the boundary of equivalence
classes (e.g., Microsoft Zune bug: https://en.m.wikipedia.org/wiki/Leap_year_bug )
Selects elements from the “edges” of each
equivalence class, or “outliers” such as
• zero, min/max values, empty set, empty string, and null
• confusion between > and >=
• palindromes (impossible to build an FSM to recognize a palindrome code)
• etc.
14
Code Coverage:
Control-flow Testing
 Statement coverage
• Each statement executed at least once by some test case
 Edge coverage
• Every edge (branch) of the control flow is traversed at least once by some test case
 Condition coverage
• Every condition takes TRUE and FALSE outcomes at least once in some test case
 Path coverage
• Finds the number of distinct paths through the program to be traversed at least once
Constructing the control graph of a program for Edge Coverage:
a; b; if a then b; if a then b else c; while a do b;
a;
a
not a
b
a not a
b c
a a
b
a
b
not a
* Exceptions are also a form of control flow, as is concurrency or multithreading
15
Code Coverage:
State-based Testing
State-based testing defines a set of abstract states that
a software unit (object) can take and tests the unit’s
behavior by comparing its actual states to the expected
states
– This approach is popular with object-oriented systems
– Like equivalence classes, state diagrams usually are mind
constructs and may be incomplete (not showing all possible
states and transitions) or incorrect
The state of an object is defined as a constraint on the
values of its attributes
– Because the methods use the attributes in computing the
object’s behavior, the behavior depends on the object state
– An object without attributes does not have states, but still can
be unit-tested (shown later)
State-based Testing Example
 Define the relevant states as combinations of object attribute
values:
1. “Locked” ≡ defined as:
(lockDeviceArmed == true) && (numOfAttempts == 0)
2. “Accepting” ≡ defined as(*):
(lockDeviceArmed == true) && (0 < numOfAttempts < maxNumOfAttempts)
3. “Unlocked” ≡ defined as:
(lockDeviceArmed == false) && (numOfAttempts == 0)
4. “Blocked” ≡ defined as:
(lockDeviceArmed == true) && (numOfAttempts == maxNumOfAttempts)
5. “Undefined” ≡ defined as:
((numOfAttempts < 0) || (maxNumOfAttempts < numOfAttempts)) ||
((lockDeviceArmed == false) && (numOfAttempts != 0))
 Define the relevant events:
1. User entered a valid key
2. User entered an invalid key
16
(Safe Home Access System)
(*) One may argue that “Locked” is a sub-state of “Accepting” …
17
State-based Testing Example
state
event guard condition
action
transition
invalid-key [numOfAttemps  maxNumOfAttempts] /
signal-failure
invalid-key /
signal-failure
invalid-key
[numOfAttemps  maxNumOfAttempts] /
sound-alarm
Blocked
Locked
valid-key /
signal-success
valid-key /
signal-success
Unlocked
Accepting
invalid-key [numOfAttemps  maxNumOfAttempts] /
signal-failure
invalid-key /
signal-failure
invalid-key
[numOfAttemps  maxNumOfAttempts] /
sound-alarm
Blocked
Locked
valid-key /
signal-success
valid-key /
signal-success
Unlocked
Accepting
18
State-based Testing Example
invalid-key [numOfAttemps  maxNumOfAttempts] /
signal-failure
invalid-key /
signal-failure
invalid-key
[numOfAttemps  maxNumOfAttempts] /
sound-alarm
Blocked
Locked
valid-key /
signal-success
valid-key /
signal-success
Unlocked
Accepting
invalid-key [numOfAttemps  maxNumOfAttempts] /
signal-failure
invalid-key /
signal-failure
invalid-key
[numOfAttemps  maxNumOfAttempts] /
sound-alarm
Blocked
Locked
valid-key /
signal-success
valid-key /
signal-success
Unlocked
Accepting
(counting attempts)
Controller State Diagram Elements
Four states
{ Locked, Unlocked, Accepting, Blocked }
Two events
{ valid-key, invalid-key }
Five valid transitions
{ LockedUnlocked, LockedAccepting,
AcceptingAccepting, AcceptingUnlocked,
AcceptingBlocked }
19
Ensure State Coverage Conditions
 Cover all identified states at least once
(each state is part of at least one test case)
 Cover all valid transitions at least once
 Trigger all invalid transitions at least once
20
21
Practical Aspects of Unit Testing
 Mock objects:
– A test driver simulates the part of the system that invokes
operations on the tested component
– A test stub simulates the components that are called by the
tested component
 Mock objects needed because:
– The corresponding actual objects are not available
– Easier to locate faults using mock objects that are trivial
and therefore not a source of faults
 The unit to be tested is also known as the fixture
 Unit testing follows this cycle:
1. Create the thing to be tested (fixture), the driver, and the
stub(s)
2. Have the test driver invoke an operation on the fixture
3. Evaluate that the actual state equals expected state
22
Testing the KeyChecker (Unlock Use Case)
(a) (b)
k := create()
sk := getNext()
: Controller : Checker : KeyStorage
enterKey()
k : Key
val := checkKey(k)
loop
compare()
[for all stored keys]
k := create()
sk := getNext()
: Controller : Checker : KeyStorage
enterKey()
k : Key
val := checkKey(k)
loop
compare()
[for all stored keys]
k := create()
testDriver : : KeyStorage
k : Key
: Checker
loop [for all stored keys]
start()
display
result
sk := getNext()
result :=
checkKey(k)
Test driver Test stubs
Tested component
compare()
k := create()
testDriver : : KeyStorage
k : Key
: Checker
loop [for all stored keys]
start()
display
result
sk := getNext()
result :=
checkKey(k)
Test driver Test stubs
Tested component
compare()
Example Test Case
23
Listing 2-1: Example test case for the Key Checker class.
public class CheckerTest {
// test case to check that invalid key is rejected
@Test public void
checkKey_anyState_invalidKeyRejected() {
// 1. set up // no states defined for Key Checker
Checker fixture = new Checker( /* constructor params */ );
// 2. act // test driver (this object) invokes tested object (Key Checker)
Key invalidTestKey = new Key( /* setup with invalid code */ );
boolean result = fixture.checkKey(invalidTestKey);
// 3. verify // check that invalid key is rejected
assertEqual(result, false);
}
}
Test Case Method Naming
24
methodName_startingState_expectedResult
1. Set up
2. Act
3. Verify
methodName_startingState_expectedResult
1. Set up
2. Act
3. Verify
Example test case method name:
checkKey_anyState_invalidKeyRejected()
25
xUnit / JUnit
Verification of the expected result is usually done
using the assert_*_() methods that define the
expected state and report errors if the actual state
differs
http://www.junit.org/
Examples:
– assertTrue(4 == (2 * 2));
– assertEquals(expected, actual);
– assertNull(Object object);
– etc.
Another Test Case Example
26
Listing 2-2: Example test case for the Controller class.
public class ControllerTest {
// test case to check that the state Blocked is visited
@Test public void
enterKey_accepting_toBlocked() {
// 1. set up: bring the fixture to the starting state
Controller fixture = new Controller( /* constructor params */ );
// bring Controller to the Accepting state, just before it blocks
Key invalidTestKey = new Key( /* setup with invalid code */ );
for (i=0; i < fixture.getMaxNumOfAttempts(); i++) {
fixture.enterKey(invalidTestKey);
}
assertEqual( // check that the starting state is set up
fixture.getNumOfAttempts(), fixture.getMaxNumOfAttempts() – 1
);
// 2. act
fixture.enterKey(invalidTestKey);
// 3. verify
assertEqual( // the resulting state must be "Blocked"
fixture.getNumOfAttempts(), fixture.getMaxNumOfAttempts()
);
assertEqual(fixture.isBlocked(), true);
}
}
27
Integration Testing
 Key Issue:
– How to assemble individually-tested “units” and quickly locate faults
that surface during integration
 Horizontal Integration Testing
– “Big bang” integration
• Problem: hard to isolate individual unit(s) that caused an integration fault
– Bottom-up integration
– Top-down integration
– Sandwich integration
 Vertical Integration Testing
– Vertically slice the system by use cases and first integrate within
each slice (using any of the horizontal integration techniques)
28
Horizontal Integration Testing
System
hierarchy:
Bottom-up
integration
testing:
Top-down
integration
testing:
Logger DeviceCtrl
PhotoSObsrv
KeyStorage Key
KeyChecker
Controller
Level-1
Level-2
Level-3
Level-4
Logger DeviceCtrl
PhotoSObsrv
KeyStorage Key
KeyChecker
Controller
Level-1
Level-2
Level-3
Level-4
Test
Logger
Test
PhotoSObsrv
Test
DeviceCtrl
Test Key &
KeyStorage
Test KeyChecker
& KeyStorage &
Key
Test Controller &
KeyChecker & KeyStorage &
Key & Logger & PhotoSObsrv
& DeviceCtrl
Test
Logger
Test
PhotoSObsrv
Test
DeviceCtrl
Test Key &
KeyStorage
Test KeyChecker
& KeyStorage &
Key
Test Controller &
KeyChecker & KeyStorage &
Key & Logger & PhotoSObsrv
& DeviceCtrl
Test
Controller
Test
Controller &
KeyChecker
Test Controller &
KeyChecker &
KeyStorage & Key
Test Controller &
KeyChecker & KeyStorage &
Key & Logger & PhotoSObsrv
& DeviceCtrl
Test
Controller
Test
Controller &
KeyChecker
Test Controller &
KeyChecker &
KeyStorage & Key
Test Controller &
KeyChecker & KeyStorage &
Key & Logger & PhotoSObsrv
& DeviceCtrl
Implementation and testing proceeds from Level-1 (bottom) to Level-4 (top)
Implementation and testing proceeds from Level-4 (top) to Level-1 (bottom)
Advantages:
• only few mock objects need to be implemented
Drawbacks:
• end user cannot see any functionality
until late in the development process
29
Vertical Integration Testing
Developing user stories:
Each story is developed in a cycle that integrates
unit tests in the inner feedback loop and the
acceptance test in the outer feedback loop
Whole system
User
story-1
User
story-2
User
story-N
Write a
failing
unit test
Refactor
Make the
test pass
Write a failing
acceptance test
inner feedback loop
outer feedback loop
30
Logical Organization of Testing
Unit
test
Unit
test
Unit
test
Integration
test
Component
code
Component
code
Component
code
Integrated
modules
Function
test
Quality
test
Acceptance
test
Installation
test
System
test
System
in use
Ensure that each
component works
as specified
Ensures that all
components
work together
Verifies that functional
requirements are
satisfied
Verifies non-
functional
requirements
Customer
verifies all
requirements
Testing in
user
environment
( Not necessarily how it’s actually done! )
System Testing
To test the whole system in our case study of safe
home access,
we need to work with a locksmith and electrician to
check that the lock and electrical wiring are properly
working,
or with a third party software developer (if 3rd party
software is used)
Security Honeypots
A deception used to detect and study network
attacks
– Part of security testing of software systems
Honeypot Access Control
Who are the users?
Attackers:
– Access the VM set up for them
Researchers
– Access the host, the attackers’ VM
– Should not erase files by mistake…
33
Honeypot Access Control Matrix
Role Asset Attacker VM Others Attack’s VM HOST
Attacker Deploy, Read,
Write
None None
Researcher None Full Full, with confirmation
34
Asset Access Control List
Role capabilities
Honeypot Access Control
Who are the users?
Attackers
– Script kiddies: 95%
• Untrusted
• Run malware found on the internet
• Easy to protect against
– Advanced attackers: 5%
• Untrusted
• Are able to understand and evade the system
• Harder to protect against
Researchers
– Trusted
– Can erase file by mistake…
35
 Refine the access control for the new distinction!

More Related Content

Similar to lec-11 Testing.ppt (20)

6 weeks summer training in software testing,ludhiana
6 weeks summer training in software testing,ludhiana6 weeks summer training in software testing,ludhiana
6 weeks summer training in software testing,ludhiana
 
6 weeks summer training in software testing,jalandhar
6 weeks summer training in software testing,jalandhar6 weeks summer training in software testing,jalandhar
6 weeks summer training in software testing,jalandhar
 
6months industrial training in software testing, ludhiana
6months industrial training in software testing, ludhiana6months industrial training in software testing, ludhiana
6months industrial training in software testing, ludhiana
 
Black box testing
Black box testingBlack box testing
Black box testing
 
Slides chapters 13-14
Slides chapters 13-14Slides chapters 13-14
Slides chapters 13-14
 
prova4
prova4prova4
prova4
 
provalast
provalastprovalast
provalast
 
test3
test3test3
test3
 
test2
test2test2
test2
 
provoora
provooraprovoora
provoora
 
prova3
prova3prova3
prova3
 
stasera1
stasera1stasera1
stasera1
 
provarealw2
provarealw2provarealw2
provarealw2
 
prova5
prova5prova5
prova5
 
provarealw3
provarealw3provarealw3
provarealw3
 
finalelocale
finalelocalefinalelocale
finalelocale
 
testsfw3
testsfw3testsfw3
testsfw3
 
 
provacompleta3
provacompleta3provacompleta3
provacompleta3
 
provacompleta4
provacompleta4provacompleta4
provacompleta4
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

lec-11 Testing.ppt

  • 2. 2 Topics Overview of Software Testing 1. Make a plan for systematic testing 2. Write and run tests; test automation Designing Tests for High Coverage Practical Aspects of Unit Testing Integration and System Testing Security Testing
  • 3. Do I Need to Do Testing? Everyone who develops software does testing—that’s unavoidable The only question is whether testing is conducted haphazardly by random trial-and-error, or systematically, with a plan Why it matters? —The goal is to try as many “critical” input combinations as possible, given the time and resource constraints – i.e., to achieve as high coverage of the input space as is practical, while testing first the “highest-priority” combinations – Key issue: strategies for identifying the “highest priority” tests 3
  • 4. Overview of Software Testing  “Testing shows the presence, not the absence of bugs.” —Edsger W. Dijkstra  A fault, also called “defect” or “bug,” is an erroneous hardware or software element of a system that can cause the system to fail  Test-Driven Development (TDD) • Every step in the development process must start with a plan of how to verify that the result meets a goal • The developer should not create a software artifact (a system requirement, a UML diagram, or source code) unless they know how it will be tested  A test case is a particular choice of input data to be used in testing a program and the expected output or behavior  A test is a finite collection of test cases 4 White-box testing exploits structure within the program (assumes program code available) Black-box testing explores input space of functionality defined by an interface specification
  • 5. 5 Why Testing is Hard  Any nontrivial system cannot be completely tested – Example: testing 4-digit numeric keycodes • You never know with certainty that all 4-digit codes work as expected unless you try all • But, what happens with “incomplete” (3-digit, 2-digit) codes? Will all of them timeout to reset state? • Or, will all tuples (pairs, triplets, etc.) of successive incomplete codes timeout to the reset state?  Our goal is to find faults as cheaply and quickly as possible. – Ideally, we would design a single “right” test case to expose each fault and run it  In practice, we have to run many “unsuccessful” test cases that do not expose any faults  A key tradeoff of testing: – testing as many potential cases as possible (high degree of “test coverage”) while keeping the economic costs limited  Underlying idea of software testing: – the correct behavior on “critical” test cases is representative of correct behavior on untested parts of the state space
  • 6. 6 Logical Organization of Testing Unit test Unit test Unit test Integration test Component (unit) code Component (unit) code Component (unit) code Integrated modules Function test Quality test Acceptance test Installation test System test System in use Ensure that each component works as specified Ensures that all components work together Verifies that functional requirements are satisfied Verifies non- functional requirements Customer verifies all requirements Testing in user environment (“platform”) ( Usually not done in a linear step-by-step order and completed when the last step is reached! ) Black box testing (by customer) White box testing (by developer)
  • 7. 7 Acceptance Tests – Safe Home Access Examples [ Recall Section 2.2: Requirements Engineering ]  Test with the valid key of a current tenant on his/her apartment (pass)  Test with the valid key of a current tenant on someone else’s apartment (fail)  Test with an invalid key on any apartment (fail)  Test with the key of a removed tenant on his/her previous apartment (fail)  Test with the valid key of a just-added tenant on his/ her apartment (pass) Input data Expected result ( “black box” testing: focus on the external behavior )
  • 8. Example: Test Case for Use Case 8 8 Test-case Identifier: TC-1 Use Case Tested: UC-1, main success scenario, and UC-7 Pass/fail Criteria: The test passes if the user enters a key that is contained in the database, with less than a maximum allowed number of unsuccessful attempts Input Data: Numeric keycode, door identifier Test Procedure: Expected Result: Step 1. Type in an incorrect keycode and a valid door identifier System beeps to indicate failure; records unsuccessful attempt in the database; prompts the user to try again Step 2. Type in the correct keycode and door identifier System flashes a green light to indicate success; records successful access in the database; disarms the lock device [ Recall Section 2.3.3: Detailed Use Case Specification ]
  • 9. Test Coverage Test coverage measures the degree to which the specification or code of a software program has been exercised by tests – “Big picture”: Specification testing focuses on the coverage of the input space, without necessarily testing each part of the software  Acceptance tests – “Implementation details”: Code coverage measures the degree to which the elements of the program source code have been tested  Unit tests 9
  • 10. Heuristic: Some Tests are More “Critical” than Others Test cases should be prioritized—some tests are more likely to uncover faults Tests are about finding developer errors, and people are prone to make certain kind of errors Some tests can easier pinpoint problems than others (some) Heuristics for achieving high coverage: (could be applied individually or in combination) – equivalence testing – boundary testing – control-flow testing – state-based testing 10 mostly for “black-box” testing mostly for “white-box” testing
  • 11. 11 Input Space Coverage: Equivalence Testing  Equivalence testing is a black-box testing method that divides the space of all possible inputs into equivalence groups such that the program is expected to “behave the same” on each input from the same group • Assumption: A well-intentioned developer may have made mistakes that affect a whole class of input values • Assumption: We do not have any reason to believe that the developer intentionally programmed special behavior for any input combinations that belong to a single class of input values  Two steps: 1. partitioning the values of input parameters into equivalence groups 2. choosing the test input values from each group Equivalence classes: 0 100 valid equivalence class invalid equivalence classes 0 100 valid equivalence class invalid equivalence classes
  • 12. 12 Heuristics for Finding Equivalence Classes  For an input parameter specified over a range of values, e.g., a number or a letter, partition the value space into one valid and two invalid equivalence classes  For an input parameter specified with a single value, e.g., a unique “security code,” partition the value space into one valid and two invalid equivalence classes  For an input parameter specified with a set of values, e.g., day or month names, partition the value space into one valid and one invalid equivalence class  For an input parameter specified as a Boolean value, partition the value space into one valid and one invalid equivalence class
  • 13. 13 Input Space Coverage: Boundary Testing Boundary testing is a special case of equivalence testing that focuses on the boundary values of input parameters – Based on the assumption that developers often overlook special cases at the boundary of equivalence classes (e.g., Microsoft Zune bug: https://en.m.wikipedia.org/wiki/Leap_year_bug ) Selects elements from the “edges” of each equivalence class, or “outliers” such as • zero, min/max values, empty set, empty string, and null • confusion between > and >= • palindromes (impossible to build an FSM to recognize a palindrome code) • etc.
  • 14. 14 Code Coverage: Control-flow Testing  Statement coverage • Each statement executed at least once by some test case  Edge coverage • Every edge (branch) of the control flow is traversed at least once by some test case  Condition coverage • Every condition takes TRUE and FALSE outcomes at least once in some test case  Path coverage • Finds the number of distinct paths through the program to be traversed at least once Constructing the control graph of a program for Edge Coverage: a; b; if a then b; if a then b else c; while a do b; a; a not a b a not a b c a a b a b not a * Exceptions are also a form of control flow, as is concurrency or multithreading
  • 15. 15 Code Coverage: State-based Testing State-based testing defines a set of abstract states that a software unit (object) can take and tests the unit’s behavior by comparing its actual states to the expected states – This approach is popular with object-oriented systems – Like equivalence classes, state diagrams usually are mind constructs and may be incomplete (not showing all possible states and transitions) or incorrect The state of an object is defined as a constraint on the values of its attributes – Because the methods use the attributes in computing the object’s behavior, the behavior depends on the object state – An object without attributes does not have states, but still can be unit-tested (shown later)
  • 16. State-based Testing Example  Define the relevant states as combinations of object attribute values: 1. “Locked” ≡ defined as: (lockDeviceArmed == true) && (numOfAttempts == 0) 2. “Accepting” ≡ defined as(*): (lockDeviceArmed == true) && (0 < numOfAttempts < maxNumOfAttempts) 3. “Unlocked” ≡ defined as: (lockDeviceArmed == false) && (numOfAttempts == 0) 4. “Blocked” ≡ defined as: (lockDeviceArmed == true) && (numOfAttempts == maxNumOfAttempts) 5. “Undefined” ≡ defined as: ((numOfAttempts < 0) || (maxNumOfAttempts < numOfAttempts)) || ((lockDeviceArmed == false) && (numOfAttempts != 0))  Define the relevant events: 1. User entered a valid key 2. User entered an invalid key 16 (Safe Home Access System) (*) One may argue that “Locked” is a sub-state of “Accepting” …
  • 17. 17 State-based Testing Example state event guard condition action transition invalid-key [numOfAttemps  maxNumOfAttempts] / signal-failure invalid-key / signal-failure invalid-key [numOfAttemps  maxNumOfAttempts] / sound-alarm Blocked Locked valid-key / signal-success valid-key / signal-success Unlocked Accepting invalid-key [numOfAttemps  maxNumOfAttempts] / signal-failure invalid-key / signal-failure invalid-key [numOfAttemps  maxNumOfAttempts] / sound-alarm Blocked Locked valid-key / signal-success valid-key / signal-success Unlocked Accepting
  • 18. 18 State-based Testing Example invalid-key [numOfAttemps  maxNumOfAttempts] / signal-failure invalid-key / signal-failure invalid-key [numOfAttemps  maxNumOfAttempts] / sound-alarm Blocked Locked valid-key / signal-success valid-key / signal-success Unlocked Accepting invalid-key [numOfAttemps  maxNumOfAttempts] / signal-failure invalid-key / signal-failure invalid-key [numOfAttemps  maxNumOfAttempts] / sound-alarm Blocked Locked valid-key / signal-success valid-key / signal-success Unlocked Accepting (counting attempts)
  • 19. Controller State Diagram Elements Four states { Locked, Unlocked, Accepting, Blocked } Two events { valid-key, invalid-key } Five valid transitions { LockedUnlocked, LockedAccepting, AcceptingAccepting, AcceptingUnlocked, AcceptingBlocked } 19
  • 20. Ensure State Coverage Conditions  Cover all identified states at least once (each state is part of at least one test case)  Cover all valid transitions at least once  Trigger all invalid transitions at least once 20
  • 21. 21 Practical Aspects of Unit Testing  Mock objects: – A test driver simulates the part of the system that invokes operations on the tested component – A test stub simulates the components that are called by the tested component  Mock objects needed because: – The corresponding actual objects are not available – Easier to locate faults using mock objects that are trivial and therefore not a source of faults  The unit to be tested is also known as the fixture  Unit testing follows this cycle: 1. Create the thing to be tested (fixture), the driver, and the stub(s) 2. Have the test driver invoke an operation on the fixture 3. Evaluate that the actual state equals expected state
  • 22. 22 Testing the KeyChecker (Unlock Use Case) (a) (b) k := create() sk := getNext() : Controller : Checker : KeyStorage enterKey() k : Key val := checkKey(k) loop compare() [for all stored keys] k := create() sk := getNext() : Controller : Checker : KeyStorage enterKey() k : Key val := checkKey(k) loop compare() [for all stored keys] k := create() testDriver : : KeyStorage k : Key : Checker loop [for all stored keys] start() display result sk := getNext() result := checkKey(k) Test driver Test stubs Tested component compare() k := create() testDriver : : KeyStorage k : Key : Checker loop [for all stored keys] start() display result sk := getNext() result := checkKey(k) Test driver Test stubs Tested component compare()
  • 23. Example Test Case 23 Listing 2-1: Example test case for the Key Checker class. public class CheckerTest { // test case to check that invalid key is rejected @Test public void checkKey_anyState_invalidKeyRejected() { // 1. set up // no states defined for Key Checker Checker fixture = new Checker( /* constructor params */ ); // 2. act // test driver (this object) invokes tested object (Key Checker) Key invalidTestKey = new Key( /* setup with invalid code */ ); boolean result = fixture.checkKey(invalidTestKey); // 3. verify // check that invalid key is rejected assertEqual(result, false); } }
  • 24. Test Case Method Naming 24 methodName_startingState_expectedResult 1. Set up 2. Act 3. Verify methodName_startingState_expectedResult 1. Set up 2. Act 3. Verify Example test case method name: checkKey_anyState_invalidKeyRejected()
  • 25. 25 xUnit / JUnit Verification of the expected result is usually done using the assert_*_() methods that define the expected state and report errors if the actual state differs http://www.junit.org/ Examples: – assertTrue(4 == (2 * 2)); – assertEquals(expected, actual); – assertNull(Object object); – etc.
  • 26. Another Test Case Example 26 Listing 2-2: Example test case for the Controller class. public class ControllerTest { // test case to check that the state Blocked is visited @Test public void enterKey_accepting_toBlocked() { // 1. set up: bring the fixture to the starting state Controller fixture = new Controller( /* constructor params */ ); // bring Controller to the Accepting state, just before it blocks Key invalidTestKey = new Key( /* setup with invalid code */ ); for (i=0; i < fixture.getMaxNumOfAttempts(); i++) { fixture.enterKey(invalidTestKey); } assertEqual( // check that the starting state is set up fixture.getNumOfAttempts(), fixture.getMaxNumOfAttempts() – 1 ); // 2. act fixture.enterKey(invalidTestKey); // 3. verify assertEqual( // the resulting state must be "Blocked" fixture.getNumOfAttempts(), fixture.getMaxNumOfAttempts() ); assertEqual(fixture.isBlocked(), true); } }
  • 27. 27 Integration Testing  Key Issue: – How to assemble individually-tested “units” and quickly locate faults that surface during integration  Horizontal Integration Testing – “Big bang” integration • Problem: hard to isolate individual unit(s) that caused an integration fault – Bottom-up integration – Top-down integration – Sandwich integration  Vertical Integration Testing – Vertically slice the system by use cases and first integrate within each slice (using any of the horizontal integration techniques)
  • 28. 28 Horizontal Integration Testing System hierarchy: Bottom-up integration testing: Top-down integration testing: Logger DeviceCtrl PhotoSObsrv KeyStorage Key KeyChecker Controller Level-1 Level-2 Level-3 Level-4 Logger DeviceCtrl PhotoSObsrv KeyStorage Key KeyChecker Controller Level-1 Level-2 Level-3 Level-4 Test Logger Test PhotoSObsrv Test DeviceCtrl Test Key & KeyStorage Test KeyChecker & KeyStorage & Key Test Controller & KeyChecker & KeyStorage & Key & Logger & PhotoSObsrv & DeviceCtrl Test Logger Test PhotoSObsrv Test DeviceCtrl Test Key & KeyStorage Test KeyChecker & KeyStorage & Key Test Controller & KeyChecker & KeyStorage & Key & Logger & PhotoSObsrv & DeviceCtrl Test Controller Test Controller & KeyChecker Test Controller & KeyChecker & KeyStorage & Key Test Controller & KeyChecker & KeyStorage & Key & Logger & PhotoSObsrv & DeviceCtrl Test Controller Test Controller & KeyChecker Test Controller & KeyChecker & KeyStorage & Key Test Controller & KeyChecker & KeyStorage & Key & Logger & PhotoSObsrv & DeviceCtrl Implementation and testing proceeds from Level-1 (bottom) to Level-4 (top) Implementation and testing proceeds from Level-4 (top) to Level-1 (bottom) Advantages: • only few mock objects need to be implemented Drawbacks: • end user cannot see any functionality until late in the development process
  • 29. 29 Vertical Integration Testing Developing user stories: Each story is developed in a cycle that integrates unit tests in the inner feedback loop and the acceptance test in the outer feedback loop Whole system User story-1 User story-2 User story-N Write a failing unit test Refactor Make the test pass Write a failing acceptance test inner feedback loop outer feedback loop
  • 30. 30 Logical Organization of Testing Unit test Unit test Unit test Integration test Component code Component code Component code Integrated modules Function test Quality test Acceptance test Installation test System test System in use Ensure that each component works as specified Ensures that all components work together Verifies that functional requirements are satisfied Verifies non- functional requirements Customer verifies all requirements Testing in user environment ( Not necessarily how it’s actually done! )
  • 31. System Testing To test the whole system in our case study of safe home access, we need to work with a locksmith and electrician to check that the lock and electrical wiring are properly working, or with a third party software developer (if 3rd party software is used)
  • 32. Security Honeypots A deception used to detect and study network attacks – Part of security testing of software systems
  • 33. Honeypot Access Control Who are the users? Attackers: – Access the VM set up for them Researchers – Access the host, the attackers’ VM – Should not erase files by mistake… 33
  • 34. Honeypot Access Control Matrix Role Asset Attacker VM Others Attack’s VM HOST Attacker Deploy, Read, Write None None Researcher None Full Full, with confirmation 34 Asset Access Control List Role capabilities
  • 35. Honeypot Access Control Who are the users? Attackers – Script kiddies: 95% • Untrusted • Run malware found on the internet • Easy to protect against – Advanced attackers: 5% • Untrusted • Are able to understand and evade the system • Harder to protect against Researchers – Trusted – Can erase file by mistake… 35  Refine the access control for the new distinction!