SlideShare a Scribd company logo
UNIT TESTING
UNIT - 2
1
Prepared By: Ravi J Khimani, CSE Department, SLTIET, Rajkot
CONCEPTS
 First level of testing
 Refers to testing program units in isolation
 Commonly understood units are function, procedures or
methods
 Or we can say class in OOP is a unit
 A program unit is assumed to implement a well defined
function providing a certain level of abstraction to the
implementation of higher level functions.
2
CONCEPTS
 It is only natural to test the unit before it is integrated with
other units.
 Thus, a program unit is tested in isolation, that is, in a
stand-alone manner
 Due to two reasons
 Errors found during testing can be attributed to a specific unit
so that it can be easily fixed
 During unit testing it is desirable to verify that each distinct
execution of a program unit produces the expected result
3
CONCEPTS
 In terms of code details, a distinct execution refers
to a distinct path in the unit.
 Ideally, all possible—or as much as possible—
distinct executions are to be considered during unit
testing.
 This requires careful selection of input data for each
distinct execution
4
CONCEPTS
 Unit testing has a limited scope.
 Needs to verify, code works perfectly or not?
 a programmer needs to test a unit as follows:
 Execute every line of code. This is desirable because the
programmer needs to know what happens when a line of code is
executed. In the absence of such basic observations, surprises at a
later stage can be expensive.
 Execute every predicate in the unit to evaluate them to true and
false separately.
 Observe that the unit performs its intended function and ensure
that it contains no known errors.
5
CONCEPTS
 In spite of the above tests, there is no guarantee that a satisfactorily
tested unit is functionally correct from a system wide perspective.
 means that some errors in a program unit can only be found later, when
the unit is integrated with other units in the integration testing and
system testing phases.
 It serves no purpose to integrate an erroneous unit with other units for
the following reasons:
 (i) many of the subsequent tests will be a waste of resources
 (ii) finding the root causes of failures in an integrated system is more
resource consuming.
6
CONCEPTS
 Unit testing is performed by the programmer who writes
the program unit because the programmer is intimately
familiar with the internal details of the unit.
 The objective for the programmer is to be satisfied that
the unit works as expected with no errors
 Unit testing is conducted in two complementary phases:
 Static unit testing
 Dynamic unit testing
7
CONCEPTS
 Static Unit Testing, programmer does not execute
Unit, instead of code is examined all possible
behavior.
 Possible issues can be solved by reviewing code in
SUT.
 Dynamic Unit Testing, is totally execution based.
 After rounds of code reviewing, execution testing is
conducted to minimize possible runtime errors.
8
STATIC UNIT TESTING
 It is undergo of philosophical belief of inspection and
correction.
 Idea behind review is to find possible defects such that
they can not be converted to errors further.
 In SUT, code review applied by two methods,
INSPECTION and WALKTHROUGH.
9
STATIC UNIT TESTING
 Inspection: It is a step-by-step peer group review of a work
product, with each step checked against predetermined criteria.
 Walkthrough: It is a review where the author leads the team
through a manual or simulated execution of the product using
predefined scenarios.
 So, any of the method is a systematic approach to examine
source code in detail.
10
STATIC UNIT TESTING
 Goal: to assess the quality of product, not to assess the quality of
process to develop the product.
 It’s time consuming process
 Not perfect up to the level.
 The key to the success code review is Divide & Conquer.
 Means having an examiner inspect small parts of the unit in isolation,
 while making sure of the following:
 nothing is overlooked
 the correctness of all examined parts of the module implies the
correctness of the whole module.
11
STATIC UNIT TESTING
 Must assure the each step should simple enough.
 The objective of code review is to review the code, not to evaluate the
author of the code.
 Therefore, code review must be planned and managed in a professional
manner.
 There is a need for mutual respect, openness, trust, and sharing of
expertise in the group.
 code review consists of six steps : readiness, preparation, examination,
rework, validation, and exit.
 the process produces two types of documents, a change request (CR)
and a report.
12
STATIC UNIT TESTING
13
STEP 1: READINESS
14
 The author of the unit ensures that the unit under test is ready
for review.
 A unit is said to be ready if it satisfies the following criteria:
 Completeness: All the code relating to the unit to be reviewed must be available.
 Minimal Functionality: The code must have been tested to some extent to make
sure that it performs its basic functionalities.
 Readability: It is essential that the code is highly readable.
 Complexity: There is no need to schedule a group meeting to review
straightforward code which can be easily reviewed by the programmer
 Requirements and Design Documents: Relevant documents must be available to
the reviewer.
STEP 1: READINESS
15
 People involved in review process are informed for group meeting
before two days.
 Review Group involves a number of peoples with their roles,
which are as follows,
 Moderator: A review meeting is chaired by the moderator. The
moderator is a trained individual who guides the pace of
the review process.
 Author: This is the person who has written the code to be reviewed.
 Presenter: A presenter is someone other than the author of the code. It is
the presenter who presents the author’s code in the review
meeting for the following reasons:
STEP 1: READINESS
16
 an additional software developer will understand the work within
the software organization;
 if the original programmer leaves the company with a short notice,
at least one other programmer in the company knows what is
being done;
 The original programmer will have a good feeling about his or her
work, if someone else appreciates their work.
 Record-keeper: The record keeper documents the problems found during
the review process and the follow-up actions suggested.
 Reviewers: These are experts in the subject area of the code under
review.
 Observers: These are people who want to learn about the code under
review.
STEP 2: PREPARATION
17
 Before the meeting, each reviewer carefully reviews the work package.
 Each reviewer develops the following:
 List of Questions: A reviewer prepares a list of questions to be
asked, if needed, of the author to clarify issues
arising from his or her reading.
 Potential CR: A reviewer may make a formal request to make a
change. These are called change requests rather
than defect reports.
These reports are not included in defect
statistics related to the product.
 Suggested Improvement Opportunities:
The reviewers may suggest how to fix the problems, if
there are any
STEP 3: EXAMINATION
18
 Includes following activities,
 The author makes a presentation of the procedural logic used in the
code, the paths denoting major computations, and the dependency .
 The presenter reads the code line by line.
 The reviewers may raise questions if the code is seen to have defects.
 Problems are not resolved in the meeting.
 The record-keeper documents the change requests and the suggestions
for fixing the problems
STEP 3: EXAMINATION
19
 Includes following activities,
 The moderator ensures that the meeting remains focused on the review
process.
 At the end of the meeting, a decision is taken regarding whether or not
to call another meeting to further review the code.
 If the review process leads to extensive rework of the code or critical
issues are identified in the process, then another meeting is generally
convened..
STEP 3: EXAMINATION – CHANGE REQUEST
20
 A CR includes the following details:
 Give a brief description of the issue or action item.
 Assign a priority level (major or minor) to a CR.
 Assign a person to follow up the issue. Since a CR documents a potential
problem, there is a need for interaction between the author
 Set a deadline for addressing a CR
STEP 3: EXAMINATION
21
STEP 4: RE-WORK
22
 At the end of the meeting, the record keeper produces a summary of the
meeting that includes the following information.
 A list of all the CRs, the dates by which those will be fixed, and the names of the
persons responsible for validating the CRs
 A list of improvement opportunities
 The minutes of the meeting (optional)
 A copy of the report is distributed to all the members of the review
group.
 After the meeting, the author works on the CRs to fix the problems.
 The author documents the improvements made to the code in the CRs.
STEP 5: VALIDATION
23
 The CRs are independently validated by the moderator or another
person designated for this purpose.
 The validation process involves checking the modified code as
documented in the CRs and ensuring that the suggested
improvements have been implemented correctly.
 The revised and final version of the outcome of the review meeting
is distributed to all the group members.
STEP 6: EXIT
24
 It is said to be complete if all of the following actions have been taken:
 Every line of code in the unit has been inspected.
 If too many defects are found in a module, the module is once again reviewed
after corrections are applied by the author.
 As a rule of thumb, if more than 5% of the total lines of code are thought to be
contentious, then a second review is scheduled.
 The author and the reviewers reach a consensus that when corrections have
been applied the code will be potentially free of defects.
 All the CRs are documented and validated by the moderator or someone else.
The author’s follow-up actions are documented.
 A summary report of the meeting including the CRs is distributed to all the
members of the review group.
CODE REVIEW MATRICES
25
 The effectiveness of static testing is limited by the ability of a
reviewer to find defects in code by visual means.
 to observe its behaviours in response to a variety of inputs.
 It is important to collect measurement of data relevant to a review
process.
 The Review process can be evaluated, made visible to the upper
management as a testing strategy, and improved to be more
effective.
CODE REVIEW MATRICES
26
 Collecting metrics during code review facilitates estimation of
review time and resources for future projects
 The following metrics can be collected from a code review:
 Number of lines of code (LOC) reviewed per hour
 Number of CRs generated per thousand lines of code (KLOC)
 Number of CRs generated per hour
 Total number of CRs generated per project
 Total number of hours spent on code review per project
DEFECT PREVENTION – WHAT IS?
27
 It is in the best interest of the programmers in particular and the
company in general to reduce the number of CRs generated during
code review.
 Because CRs - indications of potential problems - must be resolved.
 Addressing CRs - spending more resources and potentially delay in
project.
 Therefore, it is essential to adopt the concept of defect prevention.
DEFECT PREVENTION - GUIDELINES
28
These guidelines focus on incorporating suitable mechanisms into
the code:
 Build internal diagnostic tools, also known as instrumentation
code, into the units
 Provides information about the internal states of the units
 allow programmers to realize built-in tracking and tracing
mechanisms
 Instrumentation plays a passive role in dynamic unit testing
 Use standard controls to detect possible occurrences of error
conditions.
DEFECT PREVENTION - GUIDELINES
29
 Ensure that code exists for all return values, some of which may be
invalid.
 Ensure that counter data fields and buffer overflow and underflow
are appropriately handled.
 Provide error messages and help texts from a common source so
that changes in the text do not cause inconsistency.
 Validate input data, such as the arguments, passed to a function.
 Use assertions (act of stating something) to detect impossible
conditions, undefined uses of data, and undesirable program
behaviour.
DEFECT PREVENTION – USE OF ASSERTION
30
 Assertion should be routinely used to perform the following kinds
of checks:
 Ensure that preconditions are satisfied before beginning to execute a
unit.
 Ensure that the expected post conditions are true while exiting from the
unit
 Ensure that the invariants hold. That is, check invariant states —
conditions which are expected not to change during the execution of a
piece of code.
 Leave assertions in the code. You may deactivate them in the
released version of code
 Fully document the assertions that appear to be unclear.
DEFECT PREVENTION
31
 After every major computation, reverse-compute the input(s) from
the results in the code itself. Then compare the outcome with the
actual inputs for correctness.
 In systems involving message passing, buffer management is an
important internal activity.
 Develop a timer routine which counts down from a preset time
until it either hits zero or is reset.
 Include a loop counter within each loop. If the loop is ever
executed less than the minimum possible number of times or more
than the maximum possible number of times, then invoke an
exception handler routine.
DYNAMIC UNIT TESTING
32
 Execution-based unit testing.
 this execution differs from ordinary execution in the following way:
 A unit under test is taken out of its actual execution environment.
 The actual execution environment is emulated by writing more code
 The outcome of such an execution is collected in a variety of ways, such as
straightforward observation on a screen, logging on files, and software
instrumentation of the code to reveal run time behaviour
 The context of a unit test consists of two parts:
 a caller of the unit
 all the units called by that unit.
DYNAMIC UNIT TESTING - STRUCTURE
33
 The caller unit is
known as a test
driver.
 all the emulations of
the units called by
the unit under test
are called stubs
 The test driver and
the stubs are
together called
scaffolding
DYNAMIC UNIT TESTING - STRUCTURE
34
 Test Driver
 A test driver is a program that invokes the unit under test.
 input values received from the driver and returns a value to the driver.
 The driver compares the actual outcome with the expected outcome
 The test driver functions as the main unit in the execution process.
 Stub
 A stub is a “dummy subprogram” that replaces a unit that is called by the
unit under test.
 A stub performs two tasks. First, it shows an evidence that the stub was, in
fact, called.
 Second, the stub returns a precompiled value to the caller so that the unit
under test can continue its execution.
DYNAMIC UNIT TESTING - STRUCTURE
35
 A test driver and the stubs for a unit should be reusable
and maintainable.
 For each unit, there should be one dedicated test driver
and several stubs as required
 the test driver should not depend on the external input
data files
 Any modification to the driver to accommodate changes
in one of the units under test may have side effects in
testing the other units
DYNAMIC UNIT TESTING - STRUCTURE
36
 The test driver should have the capability to determine the
success or failure.
 the driver should also check for memory leaks and problems
in allocation and de-allocation of memory.
 The test driver and stubs are tightly coupled with the unit
under test and should accompany the unit throughout its life
cycle
 The low-level design document provides guidance for the
selection of input test data that are likely to uncover faults.
DYNAMIC UNIT TESTING – SELECTION OF DATA
37
 Selection of Data Based on Following Techniques:
 Control Flow Testing
 Draw a control flow graph from a program unit;
 Select a few control flow testing criteria;
 Identify paths in the control flow graph to satisfy the selection
criteria;
 Derive path predicate expressions from the selected paths;
 By solving the path predicate expression for a path,
DYNAMIC UNIT TESTING
38
 Data Flow Testing
 Draw a data flow graph from a program unit;
 Select a few data flow testing criteria;
 Identify paths in the data flow graph to satisfy the selection criteria;
 Derive path predicate expressions from the selected paths;
 By solving the path predicate expression, generate values of the
inputs to the program unit that are considered as a test case to
exercise the corresponding path
DYNAMIC UNIT TESTING
39
 Domain Testing
 In control flow and data flow testing, no specific types of faults are
considered for detection.
 New approach for fault detection.
 In this approach, a category of faults called domain errors are defined
and then test data are selected to catch those faults.
DYNAMIC UNIT TESTING
40
 Functional Program Testing:
 Identify the input and output domains of a program
 For a given input domain, select some special values and compute the
expected outcome;
 For a given output domain, select some special values and compute
the input values that will cause the unit to produce those output
values;
 Consider various combinations of the input values chosen above.
MUTATION TESTING - INTRODUCTION
41
 Introduced in 1970, originally proposed by Dick Lipton.
 Mutation testing is a technique that focuses on measuring the adequacy
(quality) of test data
 Intention behind it to expose and locate weaknesses in test cases
 Should be used to supplement traditional unit testing techniques.
 What is Mutation? : “A mutation of a program is a modification of the
program created by introducing single, small, legal syntactic change in
the code.”
 What is Mutant? : “A modified program so obtained is called a mutant”
MUTATION TESTING - INTRODUCTION
42
 A mutant is said to be killed when the execution of a test case
causes it to fail and the mutant is considered to be dead.
 Some mutants are equivalent to the given program.
 The result of executing a mutant may be different from the
expected result.
 But a test suite does not detect the failure because it does
not have the right test case.
MUTATION TESTING - INTRODUCTION
43
 In this scenario the mutant is called killable or stubborn, that
is, the existing set of test cases is insufficient to kill it.
 What is Mutation Score? : A mutation score for a set of test
cases is the percentage of non-equivalent mutants killed by
the test suite.
 What is mutation adequate? : The test suite is said to be
mutation adequate if its mutation score is 100%.
MUTATION TESTING – ANALYSIS PROCESS
44
 Mutation analysis takes two steps:
 The adequacy of an existing test suite is determined to
distinguish the given program from its mutants. (non-
equivalent mutants that could not be identified are
Stubborn)
 New test cases are added to the existing test suite to kill
the stubborn mutants.
MUTATION TESTING – EXAMPLE
45
Program
Test Suit
MUTATION TESTING – EXAMPLE
46
MUTATION TESTING – EXAMPLE ANALYSIS
 If we calculate the mutation score, we see that we created four
mutants, and two of them were killed.
 Means the mutation score is 50%, assuming that mutants 1 and 3 are
non-equivalent.
 The score is found to be low. It is low because we assumed that
mutants 1 and 3 are non-equivalent to the original program.
 We have to show that either mutants 1 and 3 are equivalent mutants or
those are killable. If those are killable, we need to add new test cases to
kill these two mutants.
47
MUTATION TESTING – TWO ASSUMPTION
 Competent Programmer Hypothesis:
 This assumption states that programmers are generally competent, and
they do not create “random” programs.
 Therefore, we can assume that for a given problem a programmer will
create a correct program except for simple errors.
 The mutants to be considered are the ones falling within a small deviation
from the original program.
 Such mutants are obtained by systematically and mechanically applying a
set of transformations, called mutation operators.
48
MUTATION TESTING – TWO ASSUMPTION
 Coupling Effect:
 The assumption can be restated as complex faults are coupled to
simple faults in such a way that a test suite detecting all simple
faults in a program will detect most of the complex faults.
 If the software contains a fault, there will usually be a set of mutants
that can only be killed by a test case that also detect that fault.
49
DEBUGGING
 The process of determining the cause of a failure is known as
debugging.
 Debugging occurs as a consequence of a test revealing a failure.
 Myers proposed three approaches to debugging:
 Brute Force
 Cause Elimination
 Back Tracking
 software engineers notice newly discovered faults while
debugging . The best way to deal with such faults is to file CR.
50
DEBUGGING – BRUTE FORCE
 The brute-force approach to debugging is preferred by many programmers
 Here, “let the computer find the error” philosophy is used.
 Good debugging tool makes these print statements redundant.
 A dynamic debugger allows the software engineer to navigate by stepping
through the code, observe which paths have executed, and observe how
values of variables change during the controlled execution.
 Instrumentation code can be built into the source code to detect problems and
to log intermediate values of variables for problem diagnosis.
 The log and memory dump are reviewed to understand what happened and
how the failure occurred
51
DEBUGGING – CAUSE ELIMINATION
 The cause elimination approach can be best described as a process involving
induction and deduction.
 In the induction part,
 first, all data related to the failure are collected.
 Next, the collected data are organized in terms of behaviour and symptoms, and
their relationship is studied to find a pattern to isolate the causes.
 In the deduction part,
 a list of all possible causes is developed in order of their likelihoods, and tests are
conducted to eliminate or substantiate each cause in decreasing order of their
likelihoods.
 If the initial tests indicate that a particular hypothesis shows promise, test data
are refined in an attempt to isolate the problem as needed.
52
DEBUGGING – BACKTRACKING
 the programmer starts at a point in the code where a failure was observed and
traces back the execution to the point where it occurred.
 This technique is frequently used by programmers, and this is useful in small
programs.
 the probability of tracing back to the fault decreases as the program size
increases, because the number of potential backward paths may become too
large.
53
DEBUGGING [CONT…]
 Debugging is usually a time consuming and error-prone process.
 For Given a symptom of a problem, the purpose is to isolate and determine its
specific cause. It’s done by the author itself.
 The following heuristic may be followed to isolate and correct it:
 Reproduce the symptom(s).
 Formulate some likely hypotheses for the cause of the problem
 Develop a test scenario for each hypothesis to be proved or disproved
 Prioritize the execution of test cases
 Execute the test cases in order to find the cause of a symptom
 Fix the problem.
 Document the changes which have been made.
54
TOOLS FOR UNIT TESTING
 Other kinds of tools that facilitate effective unit testing are as follows:
 Code Auditor:
 check the quality of software
 detects violations of programming, naming, and style guidelines
 suggest improvements to the structure and style of the source code.
 Bound Checker:
 Check for accidental writes into the instruction areas of memory or to any other
memory location outside the data storage area of the application
 Fills unused memory space with a signature pattern
 issue diagnostic messages when boundary violations on data items occur
55
TOOLS FOR UNIT TESTING
 Documenters:
 read source code and automatically generate descriptions and caller/callee tree
diagram or data model from the source code
 Interactive Debuggers:
 assist software developers in implementing different debugging approaches .
 have the trace-back and breakpoint capabilities for dynamic programming
 Breakpoint debuggers are based on deductive logic.
 omniscient debugger with no deduction.
56
TOOLS FOR UNIT TESTING
 In-Circuit Emulators:
 Commonly known as ICE.
 Provides a high-speed Ethernet connection between a host debugger and a target
microprocessor,
 Enabling developers to perform common source-level debugging activities.
 Memory Leak Detectors:
 test the allocation of memory to an application which requests for memory, but
fails to de-allocate.
 Identifies faults like, Illegal Reads, un-initialized memory reading, dynamic memory
overwrites, before time perform reading operations.
 Watches on Heap and keeps the track of Heap allocation in application.
57
TOOLS FOR UNIT TESTING
 Static Code (Path) Analyzer
 identify paths to test, based on the structure of the code
 dependent on source language and require the source code to be recompiled with
the tool.
 Software Inspection Support:
 Helps schedule group inspections.
 Provide status of items reviewed and follow-up actions and distribute the reports
of problem resolution.
 can be integrated with other tools, like static code analyzer.
58
TOOLS FOR UNIT TESTING
 Test Coverage Analyzer:
 measure internal test coverage, in terms of the control structure of the test object,
and report the coverage metric
 track and report what paths were exercised during dynamic unit testing.
 to identify parts of source code that were never touched by any dynamic unit test
 Test Data Generator:
 assist programmers in selecting test data that cause a program to behave in a
desired manner.
 Can Generate, test input data from source code, from description and
characteristics which is fed into tool.
 Generate equivalent classes and values to the boundaries.
59
TOOLS FOR UNIT TESTING
 Test Harness:
 supports the execution of dynamic unit tests by making it almost painless to
 - install the unit under test in a test environment,
 - drive the unit under test with input data in the expected input format,
 - generate stubs to emulate the behaviour of subordinate modules,
 - capture the actual outcome as generated by the unit under test and log
 Performance Monitors:
 The timing characteristics of software components can be monitored and
evaluated by these tools
 Evaluate the performance characteristics of the system, such as delay and
throughput
60
TOOLS FOR UNIT TESTING
 Network Analyzers:
 Network operating systems such as software that run on routers, switches, and
client/server systems are tested by network analyzers.
 ability to analyze the traffic and identify problem areas.
 Simulators and Emulators:
 To replace the real software and hardware that are currently not available
 are used for training, safety, and economy reasons.

 Traffic Generators:
 Large volumes of data needed to stress the interfaces and the integrated system
are generated by traffic generators.
61
TOOLS FOR UNIT TESTING
 Version Control:
 A version control system provides functionalities to store a sequence of revisions of
the software and associated information files under development.
 A system release is a collection of the associated files from a version control tool
perspective.
 These files may contain source code, compiled code, documentation, and
environment information, such as version of the tool used to write the software.
 The characteristics of the version control and configuration management tools are
as follows:
 Access Control Cross Referencing
 Tracking of Modification Release Generations
 System Version Management Archiving
62

More Related Content

What's hot

Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
Bhatt Balkrishna
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Sergey Podolsky
 
Software Quality Metrics
Software Quality MetricsSoftware Quality Metrics
Software Quality Metrics
Mufaddal Nullwala
 
Test effort estimation
Test effort estimationTest effort estimation
Test effort estimation
ramesh kumar
 
Testing
TestingTesting
Software testing life cycle
Software testing life cycleSoftware testing life cycle
Software testing life cycle
Garuda Trainings
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
teach4uin
 
Principles of Software testing
Principles of Software testingPrinciples of Software testing
Principles of Software testing
Md Mamunur Rashid
 
Types of software testing
Types of software testingTypes of software testing
Types of software testing
Prachi Sasankar
 
Software testing
Software testingSoftware testing
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
Confiz
 
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Ankit Prajapati
 
Code coverage
Code coverageCode coverage
Code coverage
Return on Intelligence
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
medsherb
 
Software testing metrics | David Tzemach
Software testing metrics | David Tzemach Software testing metrics | David Tzemach
Software testing metrics | David Tzemach
David Tzemach
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
kamal kotecha
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
Aliaa Monier Ismaail
 
Test Case Design
Test Case DesignTest Case Design
Test Case Design
acatalin
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 

What's hot (20)

Ch 3 Assembler in System programming
Ch 3 Assembler in System programming Ch 3 Assembler in System programming
Ch 3 Assembler in System programming
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Software Quality Metrics
Software Quality MetricsSoftware Quality Metrics
Software Quality Metrics
 
Test effort estimation
Test effort estimationTest effort estimation
Test effort estimation
 
Testing
TestingTesting
Testing
 
Software testing life cycle
Software testing life cycleSoftware testing life cycle
Software testing life cycle
 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
 
Principles of Software testing
Principles of Software testingPrinciples of Software testing
Principles of Software testing
 
Types of software testing
Types of software testingTypes of software testing
Types of software testing
 
Software testing
Software testingSoftware testing
Software testing
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
 
Code coverage
Code coverageCode coverage
Code coverage
 
Basic software-testing-concepts
Basic software-testing-conceptsBasic software-testing-concepts
Basic software-testing-concepts
 
Software testing metrics | David Tzemach
Software testing metrics | David Tzemach Software testing metrics | David Tzemach
Software testing metrics | David Tzemach
 
JSP Error handling
JSP Error handlingJSP Error handling
JSP Error handling
 
Introduction to White box testing
Introduction to White box testingIntroduction to White box testing
Introduction to White box testing
 
Test Case Design
Test Case DesignTest Case Design
Test Case Design
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 

Similar to Unit 2 Unit Testing

Software Testing Tutorials - MindScripts Technologies, Pune
Software Testing Tutorials - MindScripts Technologies, PuneSoftware Testing Tutorials - MindScripts Technologies, Pune
Software Testing Tutorials - MindScripts Technologies, Pune
sanjayjadhav8789
 
CTFL Module 03
CTFL Module 03CTFL Module 03
CTFL Module 03
Davis Thomas
 
Basic of Software Testing.pptx
Basic of Software Testing.pptxBasic of Software Testing.pptx
Basic of Software Testing.pptx
aparna14patil
 
object oriented system analysis and design
object oriented system analysis and designobject oriented system analysis and design
object oriented system analysis and design
wekineheshete
 
Object oriented sad 6
Object oriented sad 6Object oriented sad 6
Object oriented sad 6
Bisrat Girma
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
Rajesh-QA
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
Vidya-QA
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
ANKUR-BA
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
Sachin-QA
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
Fayis-QA
 
T0 numtq0nje=
T0 numtq0nje=T0 numtq0nje=
Static techniques
Static techniquesStatic techniques
Static techniques
aidul azmi
 
Manual testing by reddy
Manual testing by reddyManual testing by reddy
Manual testing by reddy
Krishna Gurjar
 
Sech1920 1200112979886874-3
Sech1920 1200112979886874-3Sech1920 1200112979886874-3
Sech1920 1200112979886874-3
Mateti Anilraja
 
Session 05 - Testing Concepts
Session 05 - Testing ConceptsSession 05 - Testing Concepts
Session 05 - Testing Concepts
PoojaLQA
 
Manual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docxManual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docx
ssuser305f65
 
What is integration testing
What is integration testingWhat is integration testing
What is integration testing
TestingXperts
 
6. Testing Guidelines
6. Testing Guidelines6. Testing Guidelines
6. Testing Guidelines
Mohammad Nasir Uddin
 
Lecture 08 (SQE, Testing, PM, RM, ME).pptx
Lecture 08 (SQE, Testing, PM, RM, ME).pptxLecture 08 (SQE, Testing, PM, RM, ME).pptx
Lecture 08 (SQE, Testing, PM, RM, ME).pptx
SirRafiLectures
 
A COMPOSITION ON SOFTWARE TESTING
A COMPOSITION ON SOFTWARE TESTINGA COMPOSITION ON SOFTWARE TESTING

Similar to Unit 2 Unit Testing (20)

Software Testing Tutorials - MindScripts Technologies, Pune
Software Testing Tutorials - MindScripts Technologies, PuneSoftware Testing Tutorials - MindScripts Technologies, Pune
Software Testing Tutorials - MindScripts Technologies, Pune
 
CTFL Module 03
CTFL Module 03CTFL Module 03
CTFL Module 03
 
Basic of Software Testing.pptx
Basic of Software Testing.pptxBasic of Software Testing.pptx
Basic of Software Testing.pptx
 
object oriented system analysis and design
object oriented system analysis and designobject oriented system analysis and design
object oriented system analysis and design
 
Object oriented sad 6
Object oriented sad 6Object oriented sad 6
Object oriented sad 6
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
 
Testing Concepts and Manual Testing
Testing Concepts and Manual TestingTesting Concepts and Manual Testing
Testing Concepts and Manual Testing
 
T0 numtq0nje=
T0 numtq0nje=T0 numtq0nje=
T0 numtq0nje=
 
Static techniques
Static techniquesStatic techniques
Static techniques
 
Manual testing by reddy
Manual testing by reddyManual testing by reddy
Manual testing by reddy
 
Sech1920 1200112979886874-3
Sech1920 1200112979886874-3Sech1920 1200112979886874-3
Sech1920 1200112979886874-3
 
Session 05 - Testing Concepts
Session 05 - Testing ConceptsSession 05 - Testing Concepts
Session 05 - Testing Concepts
 
Manual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docxManual Testing Interview Questions & Answers.docx
Manual Testing Interview Questions & Answers.docx
 
What is integration testing
What is integration testingWhat is integration testing
What is integration testing
 
6. Testing Guidelines
6. Testing Guidelines6. Testing Guidelines
6. Testing Guidelines
 
Lecture 08 (SQE, Testing, PM, RM, ME).pptx
Lecture 08 (SQE, Testing, PM, RM, ME).pptxLecture 08 (SQE, Testing, PM, RM, ME).pptx
Lecture 08 (SQE, Testing, PM, RM, ME).pptx
 
A COMPOSITION ON SOFTWARE TESTING
A COMPOSITION ON SOFTWARE TESTINGA COMPOSITION ON SOFTWARE TESTING
A COMPOSITION ON SOFTWARE TESTING
 

Recently uploaded

AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
drshikhapandey2022
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
Kuvempu University
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
MuhammadJazib15
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTERUNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
vmspraneeth
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
nedcocy
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
Kamal Acharya
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
wafawafa52
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
felixwold
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
EMERSON EDUARDO RODRIGUES
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
paraasingh12 #V08
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
ShurooqTaib
 

Recently uploaded (20)

AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
ELS: 2.4.1 POWER ELECTRONICS Course objectives: This course will enable stude...
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTERUNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
UNIT-III- DATA CONVERTERS ANALOG TO DIGITAL CONVERTER
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
一比一原版(爱大毕业证书)爱荷华大学毕业证如何办理
 
Blood finder application project report (1).pdf
Blood finder application project report (1).pdfBlood finder application project report (1).pdf
Blood finder application project report (1).pdf
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Ericsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.pptEricsson LTE Throughput Troubleshooting Techniques.ppt
Ericsson LTE Throughput Troubleshooting Techniques.ppt
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
 
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
 

Unit 2 Unit Testing

  • 1. UNIT TESTING UNIT - 2 1 Prepared By: Ravi J Khimani, CSE Department, SLTIET, Rajkot
  • 2. CONCEPTS  First level of testing  Refers to testing program units in isolation  Commonly understood units are function, procedures or methods  Or we can say class in OOP is a unit  A program unit is assumed to implement a well defined function providing a certain level of abstraction to the implementation of higher level functions. 2
  • 3. CONCEPTS  It is only natural to test the unit before it is integrated with other units.  Thus, a program unit is tested in isolation, that is, in a stand-alone manner  Due to two reasons  Errors found during testing can be attributed to a specific unit so that it can be easily fixed  During unit testing it is desirable to verify that each distinct execution of a program unit produces the expected result 3
  • 4. CONCEPTS  In terms of code details, a distinct execution refers to a distinct path in the unit.  Ideally, all possible—or as much as possible— distinct executions are to be considered during unit testing.  This requires careful selection of input data for each distinct execution 4
  • 5. CONCEPTS  Unit testing has a limited scope.  Needs to verify, code works perfectly or not?  a programmer needs to test a unit as follows:  Execute every line of code. This is desirable because the programmer needs to know what happens when a line of code is executed. In the absence of such basic observations, surprises at a later stage can be expensive.  Execute every predicate in the unit to evaluate them to true and false separately.  Observe that the unit performs its intended function and ensure that it contains no known errors. 5
  • 6. CONCEPTS  In spite of the above tests, there is no guarantee that a satisfactorily tested unit is functionally correct from a system wide perspective.  means that some errors in a program unit can only be found later, when the unit is integrated with other units in the integration testing and system testing phases.  It serves no purpose to integrate an erroneous unit with other units for the following reasons:  (i) many of the subsequent tests will be a waste of resources  (ii) finding the root causes of failures in an integrated system is more resource consuming. 6
  • 7. CONCEPTS  Unit testing is performed by the programmer who writes the program unit because the programmer is intimately familiar with the internal details of the unit.  The objective for the programmer is to be satisfied that the unit works as expected with no errors  Unit testing is conducted in two complementary phases:  Static unit testing  Dynamic unit testing 7
  • 8. CONCEPTS  Static Unit Testing, programmer does not execute Unit, instead of code is examined all possible behavior.  Possible issues can be solved by reviewing code in SUT.  Dynamic Unit Testing, is totally execution based.  After rounds of code reviewing, execution testing is conducted to minimize possible runtime errors. 8
  • 9. STATIC UNIT TESTING  It is undergo of philosophical belief of inspection and correction.  Idea behind review is to find possible defects such that they can not be converted to errors further.  In SUT, code review applied by two methods, INSPECTION and WALKTHROUGH. 9
  • 10. STATIC UNIT TESTING  Inspection: It is a step-by-step peer group review of a work product, with each step checked against predetermined criteria.  Walkthrough: It is a review where the author leads the team through a manual or simulated execution of the product using predefined scenarios.  So, any of the method is a systematic approach to examine source code in detail. 10
  • 11. STATIC UNIT TESTING  Goal: to assess the quality of product, not to assess the quality of process to develop the product.  It’s time consuming process  Not perfect up to the level.  The key to the success code review is Divide & Conquer.  Means having an examiner inspect small parts of the unit in isolation,  while making sure of the following:  nothing is overlooked  the correctness of all examined parts of the module implies the correctness of the whole module. 11
  • 12. STATIC UNIT TESTING  Must assure the each step should simple enough.  The objective of code review is to review the code, not to evaluate the author of the code.  Therefore, code review must be planned and managed in a professional manner.  There is a need for mutual respect, openness, trust, and sharing of expertise in the group.  code review consists of six steps : readiness, preparation, examination, rework, validation, and exit.  the process produces two types of documents, a change request (CR) and a report. 12
  • 14. STEP 1: READINESS 14  The author of the unit ensures that the unit under test is ready for review.  A unit is said to be ready if it satisfies the following criteria:  Completeness: All the code relating to the unit to be reviewed must be available.  Minimal Functionality: The code must have been tested to some extent to make sure that it performs its basic functionalities.  Readability: It is essential that the code is highly readable.  Complexity: There is no need to schedule a group meeting to review straightforward code which can be easily reviewed by the programmer  Requirements and Design Documents: Relevant documents must be available to the reviewer.
  • 15. STEP 1: READINESS 15  People involved in review process are informed for group meeting before two days.  Review Group involves a number of peoples with their roles, which are as follows,  Moderator: A review meeting is chaired by the moderator. The moderator is a trained individual who guides the pace of the review process.  Author: This is the person who has written the code to be reviewed.  Presenter: A presenter is someone other than the author of the code. It is the presenter who presents the author’s code in the review meeting for the following reasons:
  • 16. STEP 1: READINESS 16  an additional software developer will understand the work within the software organization;  if the original programmer leaves the company with a short notice, at least one other programmer in the company knows what is being done;  The original programmer will have a good feeling about his or her work, if someone else appreciates their work.  Record-keeper: The record keeper documents the problems found during the review process and the follow-up actions suggested.  Reviewers: These are experts in the subject area of the code under review.  Observers: These are people who want to learn about the code under review.
  • 17. STEP 2: PREPARATION 17  Before the meeting, each reviewer carefully reviews the work package.  Each reviewer develops the following:  List of Questions: A reviewer prepares a list of questions to be asked, if needed, of the author to clarify issues arising from his or her reading.  Potential CR: A reviewer may make a formal request to make a change. These are called change requests rather than defect reports. These reports are not included in defect statistics related to the product.  Suggested Improvement Opportunities: The reviewers may suggest how to fix the problems, if there are any
  • 18. STEP 3: EXAMINATION 18  Includes following activities,  The author makes a presentation of the procedural logic used in the code, the paths denoting major computations, and the dependency .  The presenter reads the code line by line.  The reviewers may raise questions if the code is seen to have defects.  Problems are not resolved in the meeting.  The record-keeper documents the change requests and the suggestions for fixing the problems
  • 19. STEP 3: EXAMINATION 19  Includes following activities,  The moderator ensures that the meeting remains focused on the review process.  At the end of the meeting, a decision is taken regarding whether or not to call another meeting to further review the code.  If the review process leads to extensive rework of the code or critical issues are identified in the process, then another meeting is generally convened..
  • 20. STEP 3: EXAMINATION – CHANGE REQUEST 20  A CR includes the following details:  Give a brief description of the issue or action item.  Assign a priority level (major or minor) to a CR.  Assign a person to follow up the issue. Since a CR documents a potential problem, there is a need for interaction between the author  Set a deadline for addressing a CR
  • 22. STEP 4: RE-WORK 22  At the end of the meeting, the record keeper produces a summary of the meeting that includes the following information.  A list of all the CRs, the dates by which those will be fixed, and the names of the persons responsible for validating the CRs  A list of improvement opportunities  The minutes of the meeting (optional)  A copy of the report is distributed to all the members of the review group.  After the meeting, the author works on the CRs to fix the problems.  The author documents the improvements made to the code in the CRs.
  • 23. STEP 5: VALIDATION 23  The CRs are independently validated by the moderator or another person designated for this purpose.  The validation process involves checking the modified code as documented in the CRs and ensuring that the suggested improvements have been implemented correctly.  The revised and final version of the outcome of the review meeting is distributed to all the group members.
  • 24. STEP 6: EXIT 24  It is said to be complete if all of the following actions have been taken:  Every line of code in the unit has been inspected.  If too many defects are found in a module, the module is once again reviewed after corrections are applied by the author.  As a rule of thumb, if more than 5% of the total lines of code are thought to be contentious, then a second review is scheduled.  The author and the reviewers reach a consensus that when corrections have been applied the code will be potentially free of defects.  All the CRs are documented and validated by the moderator or someone else. The author’s follow-up actions are documented.  A summary report of the meeting including the CRs is distributed to all the members of the review group.
  • 25. CODE REVIEW MATRICES 25  The effectiveness of static testing is limited by the ability of a reviewer to find defects in code by visual means.  to observe its behaviours in response to a variety of inputs.  It is important to collect measurement of data relevant to a review process.  The Review process can be evaluated, made visible to the upper management as a testing strategy, and improved to be more effective.
  • 26. CODE REVIEW MATRICES 26  Collecting metrics during code review facilitates estimation of review time and resources for future projects  The following metrics can be collected from a code review:  Number of lines of code (LOC) reviewed per hour  Number of CRs generated per thousand lines of code (KLOC)  Number of CRs generated per hour  Total number of CRs generated per project  Total number of hours spent on code review per project
  • 27. DEFECT PREVENTION – WHAT IS? 27  It is in the best interest of the programmers in particular and the company in general to reduce the number of CRs generated during code review.  Because CRs - indications of potential problems - must be resolved.  Addressing CRs - spending more resources and potentially delay in project.  Therefore, it is essential to adopt the concept of defect prevention.
  • 28. DEFECT PREVENTION - GUIDELINES 28 These guidelines focus on incorporating suitable mechanisms into the code:  Build internal diagnostic tools, also known as instrumentation code, into the units  Provides information about the internal states of the units  allow programmers to realize built-in tracking and tracing mechanisms  Instrumentation plays a passive role in dynamic unit testing  Use standard controls to detect possible occurrences of error conditions.
  • 29. DEFECT PREVENTION - GUIDELINES 29  Ensure that code exists for all return values, some of which may be invalid.  Ensure that counter data fields and buffer overflow and underflow are appropriately handled.  Provide error messages and help texts from a common source so that changes in the text do not cause inconsistency.  Validate input data, such as the arguments, passed to a function.  Use assertions (act of stating something) to detect impossible conditions, undefined uses of data, and undesirable program behaviour.
  • 30. DEFECT PREVENTION – USE OF ASSERTION 30  Assertion should be routinely used to perform the following kinds of checks:  Ensure that preconditions are satisfied before beginning to execute a unit.  Ensure that the expected post conditions are true while exiting from the unit  Ensure that the invariants hold. That is, check invariant states — conditions which are expected not to change during the execution of a piece of code.  Leave assertions in the code. You may deactivate them in the released version of code  Fully document the assertions that appear to be unclear.
  • 31. DEFECT PREVENTION 31  After every major computation, reverse-compute the input(s) from the results in the code itself. Then compare the outcome with the actual inputs for correctness.  In systems involving message passing, buffer management is an important internal activity.  Develop a timer routine which counts down from a preset time until it either hits zero or is reset.  Include a loop counter within each loop. If the loop is ever executed less than the minimum possible number of times or more than the maximum possible number of times, then invoke an exception handler routine.
  • 32. DYNAMIC UNIT TESTING 32  Execution-based unit testing.  this execution differs from ordinary execution in the following way:  A unit under test is taken out of its actual execution environment.  The actual execution environment is emulated by writing more code  The outcome of such an execution is collected in a variety of ways, such as straightforward observation on a screen, logging on files, and software instrumentation of the code to reveal run time behaviour  The context of a unit test consists of two parts:  a caller of the unit  all the units called by that unit.
  • 33. DYNAMIC UNIT TESTING - STRUCTURE 33  The caller unit is known as a test driver.  all the emulations of the units called by the unit under test are called stubs  The test driver and the stubs are together called scaffolding
  • 34. DYNAMIC UNIT TESTING - STRUCTURE 34  Test Driver  A test driver is a program that invokes the unit under test.  input values received from the driver and returns a value to the driver.  The driver compares the actual outcome with the expected outcome  The test driver functions as the main unit in the execution process.  Stub  A stub is a “dummy subprogram” that replaces a unit that is called by the unit under test.  A stub performs two tasks. First, it shows an evidence that the stub was, in fact, called.  Second, the stub returns a precompiled value to the caller so that the unit under test can continue its execution.
  • 35. DYNAMIC UNIT TESTING - STRUCTURE 35  A test driver and the stubs for a unit should be reusable and maintainable.  For each unit, there should be one dedicated test driver and several stubs as required  the test driver should not depend on the external input data files  Any modification to the driver to accommodate changes in one of the units under test may have side effects in testing the other units
  • 36. DYNAMIC UNIT TESTING - STRUCTURE 36  The test driver should have the capability to determine the success or failure.  the driver should also check for memory leaks and problems in allocation and de-allocation of memory.  The test driver and stubs are tightly coupled with the unit under test and should accompany the unit throughout its life cycle  The low-level design document provides guidance for the selection of input test data that are likely to uncover faults.
  • 37. DYNAMIC UNIT TESTING – SELECTION OF DATA 37  Selection of Data Based on Following Techniques:  Control Flow Testing  Draw a control flow graph from a program unit;  Select a few control flow testing criteria;  Identify paths in the control flow graph to satisfy the selection criteria;  Derive path predicate expressions from the selected paths;  By solving the path predicate expression for a path,
  • 38. DYNAMIC UNIT TESTING 38  Data Flow Testing  Draw a data flow graph from a program unit;  Select a few data flow testing criteria;  Identify paths in the data flow graph to satisfy the selection criteria;  Derive path predicate expressions from the selected paths;  By solving the path predicate expression, generate values of the inputs to the program unit that are considered as a test case to exercise the corresponding path
  • 39. DYNAMIC UNIT TESTING 39  Domain Testing  In control flow and data flow testing, no specific types of faults are considered for detection.  New approach for fault detection.  In this approach, a category of faults called domain errors are defined and then test data are selected to catch those faults.
  • 40. DYNAMIC UNIT TESTING 40  Functional Program Testing:  Identify the input and output domains of a program  For a given input domain, select some special values and compute the expected outcome;  For a given output domain, select some special values and compute the input values that will cause the unit to produce those output values;  Consider various combinations of the input values chosen above.
  • 41. MUTATION TESTING - INTRODUCTION 41  Introduced in 1970, originally proposed by Dick Lipton.  Mutation testing is a technique that focuses on measuring the adequacy (quality) of test data  Intention behind it to expose and locate weaknesses in test cases  Should be used to supplement traditional unit testing techniques.  What is Mutation? : “A mutation of a program is a modification of the program created by introducing single, small, legal syntactic change in the code.”  What is Mutant? : “A modified program so obtained is called a mutant”
  • 42. MUTATION TESTING - INTRODUCTION 42  A mutant is said to be killed when the execution of a test case causes it to fail and the mutant is considered to be dead.  Some mutants are equivalent to the given program.  The result of executing a mutant may be different from the expected result.  But a test suite does not detect the failure because it does not have the right test case.
  • 43. MUTATION TESTING - INTRODUCTION 43  In this scenario the mutant is called killable or stubborn, that is, the existing set of test cases is insufficient to kill it.  What is Mutation Score? : A mutation score for a set of test cases is the percentage of non-equivalent mutants killed by the test suite.  What is mutation adequate? : The test suite is said to be mutation adequate if its mutation score is 100%.
  • 44. MUTATION TESTING – ANALYSIS PROCESS 44  Mutation analysis takes two steps:  The adequacy of an existing test suite is determined to distinguish the given program from its mutants. (non- equivalent mutants that could not be identified are Stubborn)  New test cases are added to the existing test suite to kill the stubborn mutants.
  • 45. MUTATION TESTING – EXAMPLE 45 Program Test Suit
  • 46. MUTATION TESTING – EXAMPLE 46
  • 47. MUTATION TESTING – EXAMPLE ANALYSIS  If we calculate the mutation score, we see that we created four mutants, and two of them were killed.  Means the mutation score is 50%, assuming that mutants 1 and 3 are non-equivalent.  The score is found to be low. It is low because we assumed that mutants 1 and 3 are non-equivalent to the original program.  We have to show that either mutants 1 and 3 are equivalent mutants or those are killable. If those are killable, we need to add new test cases to kill these two mutants. 47
  • 48. MUTATION TESTING – TWO ASSUMPTION  Competent Programmer Hypothesis:  This assumption states that programmers are generally competent, and they do not create “random” programs.  Therefore, we can assume that for a given problem a programmer will create a correct program except for simple errors.  The mutants to be considered are the ones falling within a small deviation from the original program.  Such mutants are obtained by systematically and mechanically applying a set of transformations, called mutation operators. 48
  • 49. MUTATION TESTING – TWO ASSUMPTION  Coupling Effect:  The assumption can be restated as complex faults are coupled to simple faults in such a way that a test suite detecting all simple faults in a program will detect most of the complex faults.  If the software contains a fault, there will usually be a set of mutants that can only be killed by a test case that also detect that fault. 49
  • 50. DEBUGGING  The process of determining the cause of a failure is known as debugging.  Debugging occurs as a consequence of a test revealing a failure.  Myers proposed three approaches to debugging:  Brute Force  Cause Elimination  Back Tracking  software engineers notice newly discovered faults while debugging . The best way to deal with such faults is to file CR. 50
  • 51. DEBUGGING – BRUTE FORCE  The brute-force approach to debugging is preferred by many programmers  Here, “let the computer find the error” philosophy is used.  Good debugging tool makes these print statements redundant.  A dynamic debugger allows the software engineer to navigate by stepping through the code, observe which paths have executed, and observe how values of variables change during the controlled execution.  Instrumentation code can be built into the source code to detect problems and to log intermediate values of variables for problem diagnosis.  The log and memory dump are reviewed to understand what happened and how the failure occurred 51
  • 52. DEBUGGING – CAUSE ELIMINATION  The cause elimination approach can be best described as a process involving induction and deduction.  In the induction part,  first, all data related to the failure are collected.  Next, the collected data are organized in terms of behaviour and symptoms, and their relationship is studied to find a pattern to isolate the causes.  In the deduction part,  a list of all possible causes is developed in order of their likelihoods, and tests are conducted to eliminate or substantiate each cause in decreasing order of their likelihoods.  If the initial tests indicate that a particular hypothesis shows promise, test data are refined in an attempt to isolate the problem as needed. 52
  • 53. DEBUGGING – BACKTRACKING  the programmer starts at a point in the code where a failure was observed and traces back the execution to the point where it occurred.  This technique is frequently used by programmers, and this is useful in small programs.  the probability of tracing back to the fault decreases as the program size increases, because the number of potential backward paths may become too large. 53
  • 54. DEBUGGING [CONT…]  Debugging is usually a time consuming and error-prone process.  For Given a symptom of a problem, the purpose is to isolate and determine its specific cause. It’s done by the author itself.  The following heuristic may be followed to isolate and correct it:  Reproduce the symptom(s).  Formulate some likely hypotheses for the cause of the problem  Develop a test scenario for each hypothesis to be proved or disproved  Prioritize the execution of test cases  Execute the test cases in order to find the cause of a symptom  Fix the problem.  Document the changes which have been made. 54
  • 55. TOOLS FOR UNIT TESTING  Other kinds of tools that facilitate effective unit testing are as follows:  Code Auditor:  check the quality of software  detects violations of programming, naming, and style guidelines  suggest improvements to the structure and style of the source code.  Bound Checker:  Check for accidental writes into the instruction areas of memory or to any other memory location outside the data storage area of the application  Fills unused memory space with a signature pattern  issue diagnostic messages when boundary violations on data items occur 55
  • 56. TOOLS FOR UNIT TESTING  Documenters:  read source code and automatically generate descriptions and caller/callee tree diagram or data model from the source code  Interactive Debuggers:  assist software developers in implementing different debugging approaches .  have the trace-back and breakpoint capabilities for dynamic programming  Breakpoint debuggers are based on deductive logic.  omniscient debugger with no deduction. 56
  • 57. TOOLS FOR UNIT TESTING  In-Circuit Emulators:  Commonly known as ICE.  Provides a high-speed Ethernet connection between a host debugger and a target microprocessor,  Enabling developers to perform common source-level debugging activities.  Memory Leak Detectors:  test the allocation of memory to an application which requests for memory, but fails to de-allocate.  Identifies faults like, Illegal Reads, un-initialized memory reading, dynamic memory overwrites, before time perform reading operations.  Watches on Heap and keeps the track of Heap allocation in application. 57
  • 58. TOOLS FOR UNIT TESTING  Static Code (Path) Analyzer  identify paths to test, based on the structure of the code  dependent on source language and require the source code to be recompiled with the tool.  Software Inspection Support:  Helps schedule group inspections.  Provide status of items reviewed and follow-up actions and distribute the reports of problem resolution.  can be integrated with other tools, like static code analyzer. 58
  • 59. TOOLS FOR UNIT TESTING  Test Coverage Analyzer:  measure internal test coverage, in terms of the control structure of the test object, and report the coverage metric  track and report what paths were exercised during dynamic unit testing.  to identify parts of source code that were never touched by any dynamic unit test  Test Data Generator:  assist programmers in selecting test data that cause a program to behave in a desired manner.  Can Generate, test input data from source code, from description and characteristics which is fed into tool.  Generate equivalent classes and values to the boundaries. 59
  • 60. TOOLS FOR UNIT TESTING  Test Harness:  supports the execution of dynamic unit tests by making it almost painless to  - install the unit under test in a test environment,  - drive the unit under test with input data in the expected input format,  - generate stubs to emulate the behaviour of subordinate modules,  - capture the actual outcome as generated by the unit under test and log  Performance Monitors:  The timing characteristics of software components can be monitored and evaluated by these tools  Evaluate the performance characteristics of the system, such as delay and throughput 60
  • 61. TOOLS FOR UNIT TESTING  Network Analyzers:  Network operating systems such as software that run on routers, switches, and client/server systems are tested by network analyzers.  ability to analyze the traffic and identify problem areas.  Simulators and Emulators:  To replace the real software and hardware that are currently not available  are used for training, safety, and economy reasons.   Traffic Generators:  Large volumes of data needed to stress the interfaces and the integrated system are generated by traffic generators. 61
  • 62. TOOLS FOR UNIT TESTING  Version Control:  A version control system provides functionalities to store a sequence of revisions of the software and associated information files under development.  A system release is a collection of the associated files from a version control tool perspective.  These files may contain source code, compiled code, documentation, and environment information, such as version of the tool used to write the software.  The characteristics of the version control and configuration management tools are as follows:  Access Control Cross Referencing  Tracking of Modification Release Generations  System Version Management Archiving 62