6 Software Testing

Software Engineering · Unit 6

Software Testing

Exam-focused notes for Software Testing (Software Engineering, BIT302): what the TU syllabus asks and how it has actually been tested, with 8 solved past questions from this unit.

Software Testing in short

Testing checks that software does what it should and finds faults before users do. Testing can show that faults are present, but it can never prove that there are none.

Software Testing: notes

Types of testing

Testing has two goals. One is to show that the software meets its requirements (validation testing). The other is to find cases where it behaves wrongly (defect testing).

Verification asks "Are we building the product right?" It checks the software against its specification. Validation asks "Are we building the right product?" It checks that the software meets the customer's real needs.

Common ways to classify testing:

  • By knowledge of code: black box, white box.
  • By stage: unit, component (integration), system, release (acceptance).
  • By method: manual or automated, static (reviews, no execution) or dynamic (running the code).
  • By purpose: functional, performance, security, regression, usability.

Regression testing repeats earlier tests after a change to confirm that nothing else broke.

Development testing happens while the system is built. It has three levels: unit, component and system testing.

Black box testing

In black box testing, the tester sees only inputs and outputs, not the code. Test cases come from the specification.

Main techniques:

  • Equivalence partitioning: divide inputs into groups that the program should treat the same. Test one value from each group.
  • Boundary value analysis (BVA): faults often occur at the edges, so test values at and near the limits.

Example: a form accepts age from 18 to 60.

PartitionRangeTest values
Invalid, too lowbelow 1810
Valid18 to 6035
Invalid, too highabove 6070

Boundary tests: 17, 18, 19, 59, 60, 61.

Other techniques are decision tables, state transition testing and error guessing.

Advantages: the tester needs no programming knowledge, and it finds missing functions. Disadvantages: some code paths may never run, and tests can repeat each other.

What this unit covers

  • Types of testing
  • Black box testing
  • White box testing
  • Unit testing
  • Component testing
  • Integration testing
  • System testing
  • Release testing
  • Test-driven development approach

Test-driven development approach

2082 · 10 marks

Explain the test driven development. List its advantages and disadvantages.[10]

Show solved answer

Test Driven Development (TDD)

Note: No specific reference notes were found for this topic. The following answer is based on standard Software Engineering curriculum content appropriate for BSc CSIT, Tribhuvan University.


Definition

Test Driven Development (TDD) is a software development approach in which test cases are written before the actual code is written. The developer first writes a failing test, then writes the minimum amount of code to pass that test, and finally refactors the code. This cycle is repeated throughout the development process.

TDD follows the principle: "Write tests first, then write code to satisfy those tests."


The TDD Cycle (Red-Green-Refactor)

The core process of TDD follows three repeating steps:

1. RED    --> Write a test that FAILS (feature not yet implemented)
2. GREEN  --> Write just enough code to PASS the test
3. REFACTOR --> Clean up the code without breaking the test

This cycle is also known as the "Red-Green-Refactor" cycle.


Steps in TDD Process

  1. Add a Test

    • Before writing any functional code, write a test case for the new feature or function.
    • The test will fail initially because the feature does not exist yet.
  2. Run All Tests

    • Run the test suite to confirm the new test fails (Red phase).
    • This verifies the test is valid and the feature is truly missing.
  3. Write the Code

    • Write the minimum amount of code necessary to make the failing test pass.
    • Do not write extra or unnecessary code at this stage.
  4. Run Tests Again

    • Run all tests to confirm the new test now passes (Green phase).
    • Ensure no existing tests are broken.
  5. Refactor the Code

    • Clean up the code: remove duplication, improve readability, optimize structure.
    • Run tests again to ensure refactoring did not break anything.
  6. Repeat

    • Repeat the cycle for the next feature or requirement.

Diagram of TDD Cycle

        +------------------+
        |  Write a Test    |  <--- (Test Fails - RED)
        +--------+---------+
                 |
                 v
        +------------------+
        |  Write Code to   |  <--- (Test Passes - GREEN)
        |  Pass the Test   |
        +--------+---------+
                 |
                 v
        +------------------+
        |  Refactor Code   |  <--- (Clean Code - REFACTOR)
        +--------+---------+
                 |
                 v
           (Repeat Cycle)

Advantages of TDD

#AdvantageDescription
1Early Bug DetectionBugs are identified at an early stage since tests are written before code.
2Better Code QualityForces developers to write clean, modular, and well-structured code.
3Simplified DebuggingWhen a test fails, only the recently written code needs to be checked.
4Living DocumentationTest cases serve as documentation that describes how the system should behave.
5Confidence in RefactoringDevelopers can refactor code confidently knowing tests will catch any regression.
6Reduced Cost of ChangesDefects found early are cheaper to fix than those found after deployment.
7Better DesignEncourages loosely coupled and highly cohesive design since code must be testable.
8Faster FeedbackDevelopers get immediate feedback on whether their code works correctly.
9Regression TestingThe test suite automatically checks that new changes do not break existing functionality.
10Increased Developer ConfidenceDevelopers feel more confident releasing software when all tests pass.

Disadvantages of TDD

#DisadvantageDescription
1Slow Initial DevelopmentWriting tests before code takes extra time initially, slowing down the development speed.
2Difficult for BeginnersRequires a shift in mindset; new developers may find it hard to write tests before code.
3Maintenance OverheadAs the codebase grows, maintaining a large number of test cases becomes complex and time-consuming.
4Not Suitable for All ProjectsTDD may not be practical for small, short-lived projects or rapid prototyping.
5False Sense of SecurityPassing all tests does not guarantee the software is completely bug-free or meets user needs.
6Poorly Written TestsIf test cases are poorly designed, they may not effectively catch real bugs.
7UI Testing is DifficultTDD is less effective for testing graphical user interfaces (GUIs) and visual components.
8Requires DisciplineTDD requires strict discipline and commitment from the entire development team.
9Integration IssuesUnit tests in TDD may pass individually but integration problems may still exist.
10Legacy Code ChallengesApplying TDD to existing legacy codebases is very difficult and often impractical.

Summary

AspectDetail
Full FormTest Driven Development
Core IdeaWrite tests before writing code
CycleRed --> Green --> Refactor
GoalProduce clean, working, and well-tested software
Best Suited ForAgile and iterative development environments

Conclusion: TDD is a powerful development methodology that improves code quality, reduces bugs, and increases developer confidence. However, it requires discipline, proper training, and is most effective when applied consistently throughout the development lifecycle.

Open this answer on its own page →

2081 · 5 marks

Write short notes on: a) open-source development b) Test driven development [5]

Show solved answer

Short Notes

a) Open-Source Development

Open-source development is a software development model where the source code is made publicly available for anyone to view, use, modify, and distribute. It follows a collaborative, community-driven approach.

Key Characteristics:

  • Public Repository: Source code is hosted on platforms like GitHub, GitLab, or SourceForge, accessible to everyone.
  • Community Collaboration: Developers worldwide contribute bug fixes, new features, and improvements through pull requests and patches.
  • Transparency: All changes, discussions, and decisions are visible to the public.
  • Licensing: Governed by licenses such as GNU GPL, MIT, or Apache, which define terms of use and redistribution.
  • Peer Review: Code is reviewed by multiple contributors, improving quality and security.

Examples:

Linux, Apache, Mozilla Firefox, Python.

Advantages:

  • Reduces development cost
  • Faster bug detection and fixing
  • Encourages innovation and reuse

Disadvantages:

  • Lack of formal support
  • Inconsistent documentation
  • Security risks if code is misused

b) Test-Driven Development (TDD)

Test-Driven Development (TDD) is a software development practice where tests are written before the actual code. It follows a short, repetitive development cycle.

The TDD Cycle (Red-Green-Refactor):

StepDescription
RedWrite a test that fails (since code does not exist yet)
GreenWrite the minimum code necessary to pass the test
RefactorClean and improve the code without changing its behavior

Key Principles:

  • No production code is written unless there is a failing test to justify it.
  • Tests act as living documentation of the system.
  • Encourages simple, modular, and loosely coupled design.

Process Flow:

Write Failing Test --> Write Code to Pass Test --> Refactor --> Repeat

Advantages:

  • Early detection of defects
  • Improved code quality and design
  • Provides a safety net for future changes (regression testing)
  • Better requirement understanding before coding

Disadvantages:

  • Requires discipline and practice
  • Initial development may be slower
  • Difficult to apply for complex UI or legacy systems

Example:

Before writing a function add(a, b), a developer first writes:

assert add(2, 3) == 5   # Test written first

Then implements the function to make the test pass.

Open this answer on its own page →

2079 · 5 marks

Why test driven development approach is productive in software development? Explain. [5]

Test Driven Development (TDD) is a software development approach in which tests are written before the actual code is written. The developer first writes a failing test case, then writes the minimum code to pass that test, and finally refactors the code. --- --- - Since tests are written before c...

Open this answer on its own page →

Release testing

2082 · 5 marks

Explain the concept of release testing with an example. [5]

Release testing is a type of system testing where a version of a software system intended for release to customers is tested by a dedicated testing team (separate from the development team). The primary goal is to convince the supplier that the system is good enough for use, i.e., to validate tha...

Open this answer on its own page →

Unit testing

2081 · 10 marks

Explain key activities performed during Unit testing, component testing and system testing.[10]

Note: The following answer is based on standard software engineering principles (Sommerville, Pressman) as no specific curriculum notes were provided. --- Unit testing focuses on testing individual program units or modules in isolation. It is typically performed by developers. a) Test Planning - ...

Open this answer on its own page →

Black box testing

2080 · 5 marks

Differentiate between black box testing and white box testing. [5]

Black box testing is a software testing technique in which the internal structure, design, or implementation of the system is not known to the tester. The tester only focuses on the inputs and outputs of the system without any knowledge of how the system processes the data internally. - Also know...

Open this answer on its own page →

0 · 5 marks

Differentiate between black box testing and white box testing. Explain the importance of white box testing. [5]

Aspect Black Box Testing White Box Testing --------- Knowledge of Internal Structure Tester has NO knowledge of internal code/structure Tester has FULL knowledge of internal code/structure Basis of Testing Based on requirements and specifications Based on internal logic, code paths, and structure...

Open this answer on its own page →

Types of testing

0 · 5 marks

List different types of testing. Explain component testing and integration testing. [5]

The main types of software testing are: 1. Component Testing (Unit Testing) 2. Integration Testing 3. System Testing 4. Acceptance Testing 5. Regression Testing 6. Performance Testing 7. Stress Testing 8. Black-box Testing 9. White-box Testing --- Component testing (also called unit testing) is t...

Open this answer on its own page →