Ch3 UnitTesting
Ch3 UnitTesting
1
Chapter 1 - Review
1. What is total quality management (TQM)? What is the difference between TQM and TQC?
2. Explain the differences between validation and verification.
3. Explain the differences between failure, error, and fault .
4. What is a test case? What are the objectives of testing?
5. Explain the concepts of unit, integration, system, acceptance, and regression testing.
6. What are the different sources from which test cases can be selected?
7. What is the difference between fault injection and fault simulation?
8. Explain the differences between structural and functional testing.
9. What are the strengths and weaknesses of automated testing and manual testing?
10. What the difference between white box and black box testing
11. What are the broad categories of Text Execution Metrics
2
• Concept of Unit Testing
• Static Unit Testing
• Defect Prevention
• Dynamic Unit Testing
• Mutation Testing
• Debugging
3
• Step 1: Readiness
– Criteria
• Completeness – must be available
• Minimal functionality – must compile and link
• Readability -
• Sufficient Complexity to warrant group review
• Requirements and design documents –
all should be available
– Roles
• Moderator
• Author
• Presenter
• Record keeper
• Reviewers
• Observer
• Step 2: Preparation
– List of questions
– Potential Change Request (CR)
– Suggested improvement opportunities
7
Static Unit Testing (Code Review)
• Step 3: Examination
– The author makes a presentation
– The presenter reads the code
– The record keeper documents the Change Requests
(CR)
– Moderator ensures the review is on track
• Step 4: Re-work
– Make the list of all the Change Requests
– Make a list of improvements
– Record the minutes meeting
– Author works on the CRs to fix the issue
• Step 5: Validation
– CRs are independently validated
• Step 6: Exit
– A summary report of the meeting minutes is
distributes
8
Static Unit Testing (Code Review)
generated by engineering
department
– Requirement
Static Unit Testing (Code Review)
– Functional Specification
– High-level Design
– Low-level Design
– code
• In addition installation,
user, and trouble shooting
guides are developed by Table 3.1: System documents
technical documentation
group
• Goal is to reduce the number of CRs
generated during code review
– Build [internal diagnostic
tools]instrumentation code into the code
– Use standard control to detect possible
occurrences of error conditions –e.g divides by
zero
12
14
• Control flow testing (chapter 4)
– Draw a control flow graph (CFG) from a
program unit
– Select a few control flow testing criteria
– Identify a path in the CFG to satisfy the
selection criteria
Selection of test data is broadly based on the following techniques:
•
8. exit(0); }
rank is %d \n”, r);
7. printf(“Value of the
atoi(argv[r]))
6. if (atoi(argv[i]) >
5. for i = 2 to 3 do
4. {r = 1;
3. char *argv[];
2. int argc, r, i;
1. main(argc,argv)
rank is 1
Test Case 3:
rank is 2
Test Case 2:
is 3
Test Case 1:
P
programmers.
• Coupling effects
– Complex faults are coupled to simple faults in
such a way that a test suite detecting 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.
• The process of determining the cause of a
failure is known as debugging
• The purpose is to isolate and determine its
specific cause, given a symptom of a
problem
• There are three approaches to debugging
20
22
Figure 3.3: Test-first process in XP
23
Unit Testing in eXtreme Programming
it Mars.
JUnit – A Framework for Unit Testing
make assertions.
– assertTrue(Boolean condition)
– assertFalse(Boolean condition)
– assertEquals(Object expected, Object actual)
– assertEquals(int expected, int actual)
– assertEquals(double expected, double actual,
double tolerance)
– assertSame(Object expected, Object actual)
– assertNull(Object testobject)
– …
• The tester can have her own assertions.
import TestMe; // TestMe is the class whose methods are going to
be tested.
import junit.framework.*; // This contains the TestCase class.
public class MyTestSuite extends TestCase { // Create a subclass
of TestCase
public void MyTest1() { // This method is the first test case
TestMe object1 = new TestMe( ... ); // Create an instance of
TestMe with desired params
int x = object1.Method1(...); // invoke Method1 on object1
27
}
public void MyTest2() { // This method is the second test case
TestMe object2 = new TestMe( ... ); // Create another
instance of
// TestMe with desired parameters
double y = object2.Method2(...); // invoke Method2 on
object2
assertEquals(2.99, y, 0.0001d); // 2.99 is the expected
value;
// y is the actual value;
// 0.0001 is tolerance level
}
}
Figure 3.5: An example test suite
• Code auditor
– This tool is used to check the quality of the
software to ensure that it meets some
minimum coding standard
• Bound checker
– This tool can check for accidental writes into
the instruction areas of memory, or to other
28
application
which
request for
memory and
fail to de-
allocate
memory
Tools for Unit Testing
• Static code
(path) analyzer
– These tool
identify paths
to test based
on the
structure of
code such as
McCabe’s
cyclomatic
complexity
measure
Table 3.3: McCabe complexity
measure
• Software inspection support
– Tools can help schedule group inspection
• Test coverage analyzer
– These tools measure internal test coverage,
often expressed in terms of control structure of
the test object, and report the coverage metric
• Test data generator
30
packets.
• Version control
– A version control system provides
functionalities to store a sequence of revisions
of the software and associated information
files under development
Tools for Unit Testing