Software Testing Techniques: White-Box, Model-Based, and More

Question 1: White-Box Testing

What is a key characteristic of white-box test techniques?

Answer: (b) They are used both to measure coverage and to design tests to increase coverage.

Question 3: Model-Based Testing

What is Model-Based Testing?

Model-Based Testing (MBT) is a software testing approach where test cases are derived from a model representing the system’s behavior, requirements, or processes.

Question 4: Pairwise & Neighborhood Integration

Pairwise Integration:

  • A testing technique where test cases are designed to cover all possible pairs of input values.
  • Reduces the number of test cases while maintaining high defect detection.

Neighborhood Integration:

  • Focuses on testing interactions between components/modules that are directly related.
  • Used when components have dependencies on each other.

Question 5: AC System as a Finite State Machine

The AC system has:

  • Modes: WARM, COLD, DRY, AUTO.
  • Fan Movements: STOP, SWING.
  • Speeds: 0, 10, 15, 20, 25.

Finite State Machine Representation:

  • States: Defined by mode and speed (e.g., WARM-STOP-0, COLD-SWING-25).
  • Transitions: Occur when the mode or movement type changes.

Example Transitions:

  • WARM-SWING-20 → WARM-STOP-0
  • COLD-SWING-25 → COLD-STOP-0


  1. Why are both black-box and white-box techniques used?

    Answer: (a) They find different types of defects.

  2. What is the order of the following tests, from lowest to highest, left to right?

    Answer: (c) Unit > Integration > System > Acceptance

  3. Statement and decision coverage for the given test cases?

    Answer: (d) Statement coverage = 100%, Decision coverage = 75%

  4. What is Behavior-Driven Development?

    Answer:

    • Behavior-Driven Development (BDD) is a software development approach that enhances collaboration between developers, testers, and business stakeholders.
    • It uses natural language specifications (e.g., Given-When-Then) to describe expected system behavior.

    Example:

    Given a user logs into the system
    When they enter valid credentials
    Then they should be redirected to the dashboard

  5. Briefly explain top-down, bottom-up, and sandwich integration.

    Answer:

    • Top-Down Integration: Starts testing from high-level modules downwards using stubs.
    • Bottom-Up Integration: Starts testing from low-level modules upwards using drivers.
    • Sandwich Integration: A mix of both, where middle modules are tested last.
  6. Describe the AC remote system as a finite state machine.

    Answer:

    • States are based on air circulation speeds: 0, 10, 15, 20, 25.
    • Transitions depend on mode changes (WARM, COLD, DRY, AUTO) and fan movement (STOP, SWING).

    Example transitions:

    • WARM + SWING → Speed = 20
    • COLD + SWING → Speed = 25
    • DRY + STOP → Speed = 15


  1. Implement unit testing for updateStudentCgpa().

    Answer:

    • Use Mockito to mock dependencies.

    Example test:

    @Test
    void testUpdateStudentCgpa() throws Exception {
      Student student = new Student(1, 3.5);
      List<Integer> grades = Arrays.asList(80, 90, 70);
      when(studentRepository.findById(1)).thenReturn(student);
      studentCgpaService.updateStudentCgpa(1, grades);
      verify(studentRepository).save(any(Student.class));
      verify(logger).log(eq("Updated student cgpa"), any());
    }
  2. What is the branch coverage for updateStudentCgpa()?

    Answer:

    • Ensures all if-else branches execute at least once.
    • Key branches:
    • if (grades.isEmpty())
    • if (student == null)
  3. What is the condition coverage for updateStudentCgpa()?

    Answer:

    • Ensures each Boolean condition is tested for both true and false.

    Example:

    if (grades.isEmpty() || student == null)
    • Two conditions: grades.isEmpty(), student == null
    • Must test: (true, false), (false, true), (true, true), (false, false).


Implement integration testing for updateStudentCgpa() and the database.

Answer:

  • Use Spring Boot test with an in-memory database.

Example test:

@Test
void testUpdateStudentCgpaIntegration() throws Exception {
  Student student = new Student(1, 3.5);
  studentRepository.save(student);
  List<Integer> grades = Arrays.asList(80, 90, 70);
  studentCgpaService.updateStudentCgpa(1, grades);
  Student updatedStudent = studentRepository.findById(1);
  assertEquals(80.0, updatedStudent.getCgpa());
}

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@SpringBootTest
public class StudentCgpaServiceIntegrationTest {
  @Autowired
  private StudentCgpaService studentCgpaService;
  @Autowired
  private FinalGradeRepository finalGradeRepository;
  @Test
  @Transactional // Ensures rollback after test execution
  public void testUpdateStudentCgpa_Integration() throws Exception {
    FinalGrade finalGrade = new FinalGrade();
    finalGrade.setGrades(List.of(
      new WeightedGrade(4.0, 3),
      new WeightedGrade(3.5, 4)
    ));

    finalGrade = finalGradeRepository.save(finalGrade);
    studentCgpaService.updateStudentFinalGrade(finalGrade.getId(), finalGrade.getGrades());
    FinalGrade updatedFinalGrade = finalGradeRepository.findById(finalGrade.getId());
    assertEquals(3.71, updatedFinalGrade.getGrade(), 0.01);
  }
}