Testing Fundamentals

Overview

  • Course: ECM2414 – Software Development
  • Topic: Testing Fundamentals
  • Session: T1: W4-L2
  • Instructor: Prof. Solomon Oyelere
  • Department: Computer Science, University of Exeter

Testing Mindset Shift

Common Misconception

Traditional thinking: “I’ll finish coding and test if I have time”

Correct Approach

Modern understanding:

  • Testing is an integral part of the development process
  • Can actually save time overall
  • Reduces bugs and improves software quality
  • Prevention over correction philosophy

The V-Model of Software Development

Left Side: Development Phases

1. Concept of Operations

Purpose: Provides statement of goals and objectives of the system

Components:

  • Strategies, tactics, policies affecting the system
  • Contextualizes system in wider business environment
  • Clear statement of responsibilities and authorities
  • Process specifications for initiating, developing, maintaining, retiring system

2. Requirements Analysis

Core Areas:

  • Requirements Gathering: Collecting stakeholder needs
  • Requirements Analysis: Ensuring gathered requirements are:
    • Clear
    • Complete
    • Consistent
    • Unambiguous
  • Formal Recording: Documentation through:
    • Use cases
    • User stories
    • Formal lists and specifications

3. Design Phase

High-Level Design

Seen in: UML diagrams and architecture planning

Describes:

  • Platforms, systems, products, services the system depends on
  • Significant changes needed to external systems
  • Architecture diagram showing:
    • Interfaces
    • Components
    • Networks requiring specification/development
Detailed Design

Specifies: How the system will be constructed

Includes:

  • Functions/objects/methods specifications
  • Detailed implementation guidance

Critical milestone: Once detailed design is complete, tests can be written before implementation

Right Side: Testing Phases

Corresponding Test Levels

Concept of Operations     ←→     User Acceptance Testing
Requirements Analysis     ←→     System Testing  
High-Level Design        ←→     Integration Testing
Detailed Design          ←→     Unit Testing

V-Model Characteristics

Change Impact

  • Sudden design changes often due to errors on left-hand side
  • Changes and upgrades may impact entire left side depending on scope
  • Early error detection prevents costly late-stage fixes

Testing Levels Detail

1. Unit Testing

Definition: Testing individual blocks of code for correctness

Scope by Paradigm:

  • Procedural Programming: Function level
  • OO Programming: Object/class/method level

Characteristics:

  • Most widely used testing type
  • Probably done informally by most developers
  • Foundation for other testing levels

2. Integration Testing

Purpose: Test grouped components working together

Why Needed:

  • Individual components tested separately
  • Must be integrated to form final system
  • Unexpected behavior may arise at integration points
  • Interface problems between components

Types:

  • Big Bang: Integrate all at once
  • Incremental: Gradual integration
  • Top-down/Bottom-up: Directional approaches

3. System Testing

Definition: Testing the entire system as a whole

Scope:

  • Complete system functionality
  • Performance impact on wider environment
  • Resource availability effects on OS
  • Impact on other applications on same system

Characteristics:

  • End-to-end testing scenarios
  • Real-world environment simulation
  • Non-functional requirements validation

4. User Acceptance Testing (UAT)

Development: UAT plans created during requirements analysis phase
Composed by: Users (not developers)

Environment:

  • User environment resembling production
  • Realistic data usage
  • Real-world conditions

Purpose:

  • Ensure delivered system meets user requirements
  • Verify system ready for real-time use
  • Validation activity (not verification)

Validation vs Verification:

  • Validation: Are we building the right system? (UAT)
  • Verification: Are we building the system right? (Other testing)

V-Model Advantages and Disadvantages

Advantages

1. Highly Structured

  • Phases completed sequentially
  • Clear milestones and deliverables
  • Predictable timeline

2. Well-Suited for Clear Requirements

  • Works well when all requirements understood upfront
  • Stable requirements environment
  • Defined scope projects

3. Simple to Understand

  • Linear progression
  • Clear phase boundaries
  • Easy to explain to stakeholders

4. Easy to Manage

  • Each phase has definite end
  • Review points at phase completion
  • Clear progress tracking

Disadvantages

1. Inflexible to Change

  • Difficult to go back once in testing phase
  • Change functionality requires major rework
  • Late discovery of requirement issues

2. Requirements Assumption

  • Not suitable for projects where requirements might change
  • Assumes complete understanding upfront
  • Poor for exploratory projects

3. Late Working Software

  • No working software until late in cycle
  • Long feedback loops
  • Risk of building wrong system

Testing Categories

Static Testing

Definition: Assessing documents without executing code

Methods:

  • Reviews: Formal document examination
  • Walkthroughs: Guided document exploration
  • Inspections: Structured defect detection
  • Code analysis: Automated code examination

Dynamic Testing

Definition: Testing that involves executing program code

Three Approaches

1. White Box Testing

Characteristics:

  • Internals of program are known
  • Can test explicit paths through system
  • Focus on code coverage
  • Structural testing approach

Advantages:

  • Code visibility enables comprehensive path testing
  • Many paths through program can be tested
  • Internal logic validation
  • Coverage measurement possible

Disadvantages:

  • Knowledge of internals influences testing
  • Can lead to bias in test design
  • May miss user perspective
  • Developer assumptions affect test design
2. Black Box Testing

Characteristics:

  • Treats code as “black box”
  • Only concerned with functionality
  • No internal knowledge used
  • Behavioral testing approach

Advantages:

  • No knowledge of internals → no programmer bias
  • More likely to result in unexpected tests
  • User perspective focus
  • Requirements-based testing

Disadvantages:

  • High probability of testing only small number of paths
  • Limited coverage of internal logic
  • May miss edge cases in implementation
  • Cannot verify internal state changes
3. Grey Box Testing

Characteristics:

  • Know required functionality AND some implementation concepts
  • Access to data stores not user-accessible in live system
  • Hybrid approach combining white and black box
  • Code base not exposed but internal knowledge available

White Box vs Black Box Comparison

AspectWhite BoxBlack Box
KnowledgeFull internal code visibilityNo internal knowledge
Test DesignBased on code structureBased on requirements
CoverageHigh code path coverageLimited path coverage
Bias RiskHigh (programmer bias)Low (user perspective)
PerspectiveDeveloper viewpointUser viewpoint
ComplexityHigher technical complexitySimpler functional focus

Unit Tests & Code Coverage

Relationship to Coverage

  • Unit tests provide foundation for white box testing
  • Principles: Test small specific areas of functionality
  • Challenge: How to determine how much program has been tested?

Solution: Code Coverage Analysis

Code Coverage

Definition

Code coverage: Attempts to measure how much of your code has been tested (or degree to which it has been tested)

Characteristics

  • Looks at code directly (not black box)
  • Uses unit testing techniques to derive formal measure
  • Different coverage measures available
  • Complete coverage often infeasible

Industry Reality

  • Even IBM doesn’t have hard target for % code covered
  • Choice required on how much code can be covered
  • Practical limitations on achieving 100% coverage

Coverage Types

1. Function/Method Coverage

Question: Has each method had a test written (and run) on it?

Includes:

  • Constructors
  • Private methods (through indirect testing)
  • Methods not externally accessible

2. Statement Coverage

Question: Has each line of code been processed by at least one test?

Measurement: Percentage of executed statements
Goal: Exercise every line of code at least once

3. Decision Coverage

Question: Has every decision edge been traversed?

Focus: if/else branches
Requirement: Both true and false paths tested for each decision

4. Predicate Coverage

Question: Has every condition been tested?

Note: Not always same as decision coverage
Focus: Individual conditions within complex boolean expressions

Coverage Example

Sample Method

// Example from a larger Java class
public int exampleMethod(int a, int b) { 
    int c = -1; 
    if ((a >= 0) && (b > 0)) { 
        c = a * b; 
    } 
    return c; 
}

Coverage Variants

Method Coverage

exampleMethod(0, 1);  // Just call the method

Statement Coverage

exampleMethod(0, 1);  // Execute all statements including if-block

Decision Coverage

exampleMethod(0, 1);  // if condition true
exampleMethod(0, 0);  // if condition false  

Predicate Coverage

exampleMethod(0, -1);  // (a >= 0) true, (b > 0) false
exampleMethod(-1, 1);  // (a >= 0) false, (b > 0) true

Complex conditions require testing all combinations of individual predicates

Code Coverage Tools

EMMA

Target: Java 5 and 6 applications
Features:

  • Open source code coverage tool
  • Command line execution
  • IDE integration in popular IDEs
  • Statement-level coverage with color coding
  • Configurable coverage levels

JaCoCo

Target: More recent Java versions
Developer: EclEmma group
Features:

  • Modern Java support
  • Enhanced reporting
  • Better integration with build tools

Coverage Visualization

EMMA Example: Color-codes source code to denote coverage levels

  • Green: Covered statements
  • Red: Uncovered statements
  • Yellow: Partially covered (branches)

Corner Cases

Definition

Corner cases: Situations where multiple variables are at their extremes simultaneously

Relationship to Edge Cases

  • Edge cases: Variable takes maximum or minimum possible value
  • Corner cases: Many variables at extremes simultaneously

Why Important

Testing Focus Problem

  • Most tests focus on typical system uses
  • Tend to miss situations where multiple extremes occur
  • Real-world complexity often involves multiple edge conditions

Bug Characteristics

  • Most difficult bugs to find and fix
  • Rare occurrence in normal operation
  • Difficulty repeating causal situations in field
  • Complex interactions between multiple boundary conditions

Modern Approaches

Instrumentation

Large software houses instrument code to:

  • Track errors in field
  • Tackle corner cases
  • Monitor unexpected performance
  • Collect real-world usage data

Benefits

  • Field error tracking
  • Performance monitoring
  • User behavior analysis
  • Proactive bug detection

Limits of Testing

Fundamental Constraints

1. Input Complexity

  • Not possible to test every single aspect of even moderately simple system
  • Number of possible inputs too large
  • Combinatorial explosion of test scenarios

2. Path Complexity

  • Too many possible paths through system
  • Exponential growth with system complexity
  • Branching factor multiplies possibilities

Testing Philosophy

What Testing Cannot Do

Cannot assert that software functions correctly under all conditions

What Testing Can Do

Can assert that software functions incorrectly under specific conditions

Key insight: Testing finds bugs, doesn’t prove absence of bugs

Practical Implications

Test Strategy

  • Risk-based testing: Focus on high-risk areas
  • Priority-based coverage: Test most important functionality first
  • Statistical confidence: Build confidence through sampling
  • Continuous testing: Ongoing validation throughout lifecycle

Exercise: Dynamic Testing

Question: Choose correct statements about dynamic testing:

All Statements Are Correct

A. The advantage of white box testing is that we know the code and we can design tests to test many paths through the program.

  • ✅ Correct: Code visibility enables comprehensive path testing

B. White box testing may end up leading tests toward what should be happening, making tests harder to capture unexpected errors.

  • ✅ Correct: Programmer bias can limit test effectiveness

C. With black box testing, you have no knowledge of internals, so you don’t have programmer bias.

  • ✅ Correct: User perspective reduces developer assumptions

D. With black box testing, there are high probabilities that many paths through the program are not tested.

  • ✅ Correct: Limited internal visibility restricts path coverage

Key Takeaways

V-Model Insights

  1. Testing phases correspond to development phases
  2. Early planning prevents late-stage issues
  3. Structured approach provides predictability
  4. Change resistance requires careful requirement analysis

Testing Approaches

  1. White box: Internal knowledge, comprehensive paths, potential bias
  2. Black box: User perspective, functional focus, limited coverage
  3. Grey box: Hybrid approach balancing benefits

Coverage Importance

  1. Measurement guides testing effort
  2. Multiple metrics provide different insights
  3. 100% coverage rarely achievable or necessary
  4. Tools assist in coverage analysis

Testing Limitations

  1. Cannot prove correctness completely
  2. Focus on finding bugs rather than proving absence
  3. Risk-based strategies most practical
  4. Continuous improvement through field data

Summary

Testing is a critical discipline requiring:

  • Systematic approaches (V-Model)
  • Multiple perspectives (white/black/grey box)
  • Measurement techniques (code coverage)
  • Realistic expectations (limits of testing)

Understanding these fundamentals enables effective test planning and quality software delivery.

Next Topics

Upcoming: Unit tests in depth and JUnit framework practical application


Tags

softwaretesting vmodel testingfundamentals unittesting codecoverage whiteboxtesting blackboxtesting cornercases testingstrategy softwaredevelopment qualityassurance