SE--Software Coding & Testing
SE--Software Coding & Testing
Do not use
difficult to understand a piece of
goto
Well
code.
• For example, if a global variable is
changed obscurely in a called
module or some file I/O is performed
which is difficult to infer from the
function’s name and header
6
Types of Faults
Software Faults
Quite inevitable
(unavoidable) Algorithmic Logic is wrong Code reviews
Many reasons Syntax Wrong syntax; typos Compiler
7
Software Quality
8
Code Review
Code Review is carried out after Few classical programming
the module is successfully errors
Use of uninitialized variables
compiled and all the syntax
errors have been eliminated. Jumps into loops
Code Reviews are extremely Nonterminating loops
cost-effective strategies for Incompatible assignments
reduction in coding errors
and to produce high quality Array indices out of bounds
Types of
code. Reviews Improper storage allocation and
deallocation
Code Code Mismatches between actual and
Walk Inspectio formal parameter in function calls
Through n
Use of incorrect logical operators or
incorrect precedence among
operators
Improper modification of loop
9
Code Review Code Walk Through & Code Inspection
Internal External
Documentati Documentat
on ion
11
Software Documentation Cont. Internal & External Documenta
Internal External
Documentation
Documentation
It is provided through
It is the code perception features
provided as part of the source code. various types of
It is provided through appropriate module supporting documents
headers and comments embedded in the such as users’ manual
source code. software requirements
specification document
It is also provided through the useful design document
variable names, module and function test documents, etc.
headers, code indentation, code
structuring, use of enumerated types A systematic software
and constant identifiers, use of user- development style
defined data types, etc. ensures that all these
Even when code is carefully commented, documents are
meaningful variable names are still more produced in an orderly
helpful in understanding a piece of code. fashion.
Good organizations ensure good internal 12
Software Testing
Testing is the process
of exercising a program
with the specific intent
of finding errors prior
to delivery to the end
user.
Who Test
Tester
the
Software
?
Integration
Design Integrated modules
Test
Specifications
System functional Function Test Functioning
requirements system
Performance
Other software Verified, validated software
Test
requirements
Acceptance
Customer SRS Accepted system
Test
Installation
User environment System in use!
Test
15
Verification & Validation
Verification Verification Validation
Are we building the Process of evaluating Process of evaluating software
product right? products of a development at the end of the
The objective of phase to find out whether they development to determine
Verification is to make meet the specified whether software meets the
sure that the product requirements. customer expectations and
Activities involved: Reviews, Activities involved: Testing like
being develop is as per requirements.
Meetings and Inspections black box testing, white box
the requirements and testing, gray box testing
design specifications.
Validation Carried out by QA team Carried out by testing
team
Are we building the right Execution of code does not Execution of code comes
product? come under Verification under Validation
The objective of
Validation is to make sure Explains whether the Describes whether the
outputs are according to software is accepted by the
that the product meet up
inputs or not user or not
the user’s requirements Cost of errors caught is less Cost of errors caught is high
and check whether the
specifications were
correct in the first place.
16
Software Testing Strategy
Unit Testing
It concentrate on
each unit of the
software as
implemented in
Unit Testing source code
It focuses on each
Integration Testing component
Validation Testing individual,
System Testing ensuring that it
functions properly
as a unit. 17
Software Testing Strategy Cont.
25
Validation Testing – Alpha & Beta Test
Alpha Test
The alpha test is conducted at the developer’s site by a
representative group of end users
The software is used in a natural setting with the developer “looking
over the shoulders” of the users and recording errors and usage
problems
Beta
The Test
alpha tests are conducted in a controlled environment
The beta test is conducted at one or more end-user sites
Developers are not generally present
Beta test is a “live” application of the software in an environment
that can not be controlled by the developer
The customer records all problems and reports to the developers
at regular intervals
After modifications, software is released for entire customer base
26
System Testing
In system testing the software and other system elements are tested.
To test computer software, you spiral out in a clockwise direction along
streamlines that increase the scope of testing with each turn.
System testing verifies that all elements mesh properly and overall
system function/performance is achieved.
System testing is a series of different tests whose primary purpose is
to fully exercise the computer-based system.
27
Types of System Testing
Recovery
Testing It is a system test that forces the software to fail in
a variety of ways and verifies that recovery is
properly performed.
If recovery is automatic (performed by the system
itself)
Re-initialization, check pointing mechanisms, data
recovery, and restart are evaluated for correctness.
If recovery requires human intervention
Security The mean-time-to-repair (MTTR) is evaluated to
Testing It determine whether
attempts to it verify
is within acceptable
software’slimits
protection
mechanisms, which protect it from improper
penetration (access).
During this test, the tester plays the role of the
individual who desires to penetrate the system.
28
Types of System Testing Cont.
Stress Testing
It executes a system in a manner that demands
resources in abnormal quantity, frequency or volume.
A variation of stress testing is a technique called
sensitivity testing.
Performance
Testing It is designed to test the run-time performance of
software.
It occurs throughout all steps in the testing process.
Even at the unit testing level, the performance of an
individual module may be tested.
29
Types of System Testing Cont.
Deployment
Testing It exercises the software in each environment in
which it is to operate.
In addition, it examines
All installation procedures
Specialized installation software that will be used by
customers
All documentation that will be used to introduce the
software to end users
30
Acceptance Testing
It is a level of the software testing where a system is tested for
acceptability.
The purpose of this test is to evaluate the system’s compliance with the
business requirements.
It is a formal testing conducted to determine whether a system
satisfies the acceptance criteria with respect to user needs,
requirements, and business processes
It enables the customer to determine, whether to accept the system.
It is performed after System Testing and before making the system
available for actual use.
31
Views of Test Objects
32
Black Box Testing
Also known as specification-based testing
Tester has access only to running code and the specification it is supposed
to satisfy
Test cases are written with no knowledge of internal workings of the code
No access to source code
So, test cases don’t worry about structure
Emphasis is only on ensuring that the contract is met
Advantages
Scalable; not dependent on size of code
Testing needs no knowledge of implementation
Tester and developer can be truly independent of each other
Tests are done with requirements in mind
Does not excuse inconsistencies in the specifications
Test cases can be developed in parallel with code
33
Black Box Testing Cont.
Test Case Design Disadvantages
Examine pre-condition, and identify Test size will have to be small
equivalence classes Specifications must be clear,
All possible inputs such that all concise, and correct
classes are covered May leave many program
Apply the specification to input to paths untested
write down expected output Weighting of program paths is
not possible Test Case 1
Input: x1 (sat.
X)
Specification
Specificatio Exp. Output:
Operation op n- y2
Pre: X Based Test
Post: Y Case Test Case 2
Input: x2 (sat.
Design X)
Exp. Output:
y2
34
Black Box Testing Cont.
Exhausting testing is not always possible when there is a large set of
input combinations, because of budget and time constraint.
The special techniques are needed which select test-cases smartly
from the all combination of test-cases in such a way that all scenarios
are covered
Two techniques
are used
1 Equivalence 2 Boundary Value Analysis
Partitioning (BVA)
Equivalence
Partitioning
Input data for a program unit usually falls into several
partitions, e.g. all negative integers, zero, all positive numbers
Each partition of input data makes the program behave in
a similar way
Two test cases based on members from the same partition
is likely to reveal the same bugs
35
Equivalence Partitioning (Black Box Testing)
By identifying and testing one member of each partition we gain 'good'
coverage with 'small' number of test cases
Testing one member of a partition should be as good as testing any
member of the partition
Example - Equivalence
Partitioning
For binary search the following partitions exist Pick specific conditions of the
Inputs that conform to pre-conditions array
Inputs where the precondition is false The array has a single value
Inputs where the key element is a member of the array Array length is even
Inputs where the key element is not a member of the Array length is odd
array
36
Equivalence Partitioning (Black Box Testing)
Cont.
Example - Equivalence
Partitioning
Example: Assume that we must test field which accepts SPI (Semester
Performance Index) as input (SPI range is 0 to 10)
Valid Class: 0 – 10, pick any one input test data from 0 to 10
Invalid Class 1: <=-1, pick any one input test data less than or equal to -1
Invalid Class 2: >=11, pick any one input test data greater than or equal to 11
37
Boundary Value Analysis (BVA) (Black Box Testing)
It arises from the fact that most program fail at input boundaries
Boundary testing is the process of testing between extreme ends or
boundaries between partitions of the input values.
In Boundary Testing, Equivalence Class Partitioning plays a good role
Boundary Testing comes after the Equivalence Class Partitioning
The basic idea in boundary value testing is to select input variable
values at their:
Just below the Minimu Just above the
minimum m minimum
Just below the maximum Maximu Just above the
m maximum
Bound
ary
Boundary Values
38
Boundary Value Analysis (BVA) (Black Box Testing)
Suppose system asks for “a number between 100
and 999 inclusive”
99 100 999 999
The boundaries are 100 and 999 101 1000
We therefore test for values Lower boundary Upper boundary
BVA - Advantages
The BVA is easy to use and remember because of the uniformity of identified
tests and the automated nature of this technique.
One can easily control the expenses made on the testing by controlling the
number of identified test cases.
BVA is the best approach in cases where the functionality of a software is
based on numerous variables representing physical quantities.
The technique is best at user input troubles in the software.
The procedure and guidelines are crystal clear and easy when it comes to
determining the test cases through BVA.
The test cases generated through BVA are very small.
39
Boundary Value Analysis (BVA) (Black Box
Testing) Cont.
BVA - Disadvantages
This technique sometimes fails to test all the potential input values.
And so, the results are unsure.
The dependencies with BVA are not tested between two inputs.
This technique doesn’t fit well when it comes to Boolean Variables.
It only works well with independent variables that depict quantity.
40
White Box Testing
Also known as structural testing
White Box Testing is a software testing method in which the internal
structure/design/implementation of the module being tested is
known to the tester
Focus is on ensuring that even abnormal invocations are handled
gracefully
Using white-box testing methods, you can derive test cases that
Guarantee that all independent paths within a module have been exercised at
least once
Exercise all logical decisions on their true and false sides
...our
Execute all loops at their goal is to
boundaries
Exercise internal dataensure thattoall
structures ensure their validity
statements and
conditions have been
executed at least
once ...
41
White Box Testing Cont.
It is applicable to the following levels of software testing
Unit Testing: For testing paths within a unit
Integration Testing: For testing paths between units
System Testing: For testing paths between subsystems
Advantage Disadvant
s
Testing ages
Since tests can be very complex, highly
can be
commenced at an skilled resources are required, with thorough
earlier stage as one knowledge of programming and
need not wait for the implementation
GUI to be available. Test script maintenance can be a burden, if
Testing the implementation changes too frequently
is more
thorough, with the Since this method of testing is closely tied with
possibility of covering the application being testing, tools to cater to
every kind of implementation/platform may not
most paths be readily available
42
White-box testing strategies
One white-box testing strategy is said to be stronger than another
strategy, if all types of errors detected by the first testing strategy is also
detected by the second testing strategy, and the second testing strategy
additionally detects some more types of errors.
White-box testing
strategies
1 Statement 2 Branch coverage 3 Path coverage
coverage
Statement
coverage
It aims to design test cases so that every statement in a program is
executed at least once
Principal idea is unless a statement is executed, it is very hard to determine if an
error exists in that statement
Unless a statement is executed, it is very difficult to observe whether it causes
failure due to some illegal memory access, wrong result computation, etc.
43
White-box testing strategies Cont.
Consider the Euclid’s GCD computation algorithm
3 x= x – y;
4 else y= y – x;
5 }
6 return x;
}
44
White-box testing strategies Cont.
Branch Path Coverage
coverage
In the branch coverage-based In this strategy test cases are
testing strategy, test cases are executed in such a way that every
designed to make each path is executed at least once
branch condition to assume All possible control paths taken,
true and false values in turn including
It is also known as edge All loop paths taken zero, once
Testing as in this testing and multiple items in technique
scheme, each edge of a The test case are prepared based
program’s control flow graph is on the logical complexity measure
of the procedure design
traversed at least once
Branch coverage guarantees Flow graph, Cyclomatic
statement coverage, so it is Complexity and Graph Metrices
stronger strategy compared to are used to arrive at basis path.
Statement Coverage.
45
What is Cyclomatic Complexity V(G)?
47
Graph Complexity (Cyclomatic Complexity)
V(G) Cont.
48
Cyclomatic Complexity V(G) – Basis Path
Testing
49
What is the Cyclomatic Complexity V(G)?
while (i<10) {
System.out.printf("i is %d", i);
if (i%2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
}
}
50
What is the Cyclomatic Complexity V(G)?
51
Grey Box Testing
Combination of white box and black box testing
Tester has access to source code, but uses it in a restricted manner
Test cases are still written using specifications based on expected
outputs for given input
These test cases are informed by program code structure
52
Testing Web Applications
WebApp testing is a collection of related activities with
a single goal to uncover errors in WebApp content,
function, usability, navigability, performance,
capacity, and security
To accomplish this, a testing strategy that encompasses
both reviews and executable testing is applied.
Dimensions of
Quality
Content is evaluated at both a syntactic and
semantic level.
At the syntactic level spelling, punctuation, and
grammar are assessed for text-based documents.
At a semantic level correctness of information
presented, Consistency across the entire content
object and related objects, and lack of ambiguity
are all assessed.
53
Dimensions of Quality Cont.
Function is tested to uncover errors that indicate lack of conformance to
customer requirements
Structure is assessed to ensure that it properly delivers WebApp
content
Usability is tested to ensure that each category of user is supported by
the interface and can learn and apply all required navigation.
Navigability is tested to ensure that all navigation syntax and
semantics are exercised to uncover any navigation errors
Ex., dead links, improper links, and erroneous links
Performance is tested under a variety of operating conditions,
configurations and loading
to ensure that the system is responsive to user interaction and handles
extreme loading
Compatibility is tested by executing the WebApp in a variety of different
host configurations on both the client and server sides
Interoperability is tested to ensure that the WebApp properly interfaces
54
Content Testing User Interface Testing
Errors in WebApp content can be Verification and validation of a
as trivial as minor typographical WebApp user interface occurs at
errors or three distinct points
as significant as incorrect
1. During requirements analysis
information, improper the interface model is reviewed to
organization, or violation of ensure that it conforms to
intellectual property laws stakeholder requirements
Content testing attempts to 2. During design
uncover these and many other the interface design model is
problems before the user reviewed to ensure that generic
quality criteria established for all
encounters them user interfaces have been achieved
Content testing combines both 3. During testing
reviews and the generation of the focus shifts to the execution of
executable test cases application-specific aspects of user
Reviews are applied to uncover interaction as they are manifested by
interface syntax and semantics.
semantic errors in content
In addition, testing provides a final
Executable testing is used to
assessment of usability 55
Component-Level Testing
Navigation Testing
Component-level testing The job of navigation testing is
(function testing), focuses on a to ensure that
set of tests that attempt to the mechanisms that allow the
uncover errors in WebApp WebApp user to travel through the
functions. WebApp are all functional and,
to validate that each Navigation
Each WebApp function is a Semantic Unit (NSU) can be
software component achieved by the appropriate user
(implemented in one of a variety category
of programming languages) Navigation mechanisms should
WebApp function can be tested be tested are
using black-box (and in some cases, Navigation links,
white-box) techniques.
Redirects,
Component-level test cases are Bookmarks,
often driven by forms-level input. Frames and framesets,
Once forms data are defined, the Site maps,
user selects a button or other Internal search engines.
control mechanism to initiate
execution. 56
Configuration Testing Security Testing
Configuration variability and Security tests are designed
instability are important factors that to probe
make WebApp testing a challenge. vulnerabilities of the client-
Hardware, operating system(s), side environment,
the network communications
browsers, storage capacity, that occur as data are passed
network communication speeds, from client to server and back
and a variety of other client-side again, and
factors are difficult to predict for the server-side environment.
each user. Each of these domains can
One user’s impression of the WebApp be attacked, and it is the job
and the manner in which he/she of the security tester to
interacts with it can differ uncover weaknesses
significantly. that can be exploited by those
Configuration testing is to test a with the intent to do so.
set of probable client-side and server-
side configurations
to ensure that the user experience 57
Performance Testing
Performance testing is used to uncover
performance problems that can result from lack of server-side resources,
inappropriate network bandwidth,
inadequate database capabilities,
faulty or weak operating system capabilities,
poorly designed WebApp functionality, and
other hardware or software issues that can lead to degraded client-server
performance
58
Testing Object Oriented Applications
Unit Testing in the OO Context
The concept of the unit testing changes in object-
oriented software
Encapsulation drives the definition of classes
and objects
Means, each class and each instance of a class (object)
packages attributes (data) and the operations (methods
or services) that manipulate these data
Rather than testing an individual module, the
smallest testable unit is the encapsulated class
Unlike unit testing of conventional software,
which focuses on the algorithmic detail of a module and
the data that flows across the module interface,
class testing for OO software is driven by the
operations encapsulated by the class and the state
behavior of the class
59
Integration Testing in the OO Context
Object-oriented software does not have a hierarchical control
structure,
conventional top-down and bottom-up integration strategies have little
meaning
There are two different strategies for integration testing of OO systems.
1. Thread-based testing
integrates the set of classes required to respond to one input or event for the system
Each thread is integrated and tested individually
Regression testing is applied to ensure that no side effects occur
2. Use-based testing
begins the construction of the system by testing those classes (called independent
classes) that use very few (if any) of server classes
After the independent classes are tested, the next layer of classes, called dependent
classes, that use the independent classes are tested
Cluster testing is one step in the integration testing of OO software
Here, a cluster of collaborating classes is exercised by designing test
cases that attempt to uncover
60
Validation Testing in an OO Context
At the validation or system level, the details of class connections
disappear
Like conventional validation, the validation of OO software focuses on
user-visible actions and user-recognizable outputs from the system
To assist in the derivation of validation tests, the tester should draw upon
use cases that are part of the requirements model
Conventional black-box testing methods can be used to drive
validation tests
61
62
63
64
65
66
67
Thank
You