Skip to main content

Black Box Testing

Prime Numbers Testing Problem

Black Box Testing

📜 Story

BUGA is working on his stone computer.
His task? To test a function that checks if a number is prime!

But... there's a big problem – BUGA has no idea what a prime number is, let alone how to test one!
😱 Help him through this journey as he learns about equivalence partitioning, boundary value analysis, and unit testing.

Let’s guide BUGA step by step on how to properly test his function! 🔍🔥


🛠 Step 1: Understanding the Problem

Understanding the inputs and outputs

✅ BUGA's Dilemma:

"Me need to test… PRIME? But what PRIME? Me only know fire and rocks!" 🔥🪨

Before BUGA can test anything, he needs to understand:

  • What is a prime number?
  • What does the function take as input?
  • What does it return as output?
  • What are the pre and post conditions of the function?

📌 Task: Define the function specification

Help BUGA by filling in this table:

AspectDescription
Function NameisPrime
Input?
Preconditions?
Output?
Postconditions?

✍️ Fill in the missing parts to help BUGA understand the function!


🛠 Step 2: Splitting Inputs into Equivalence Classes

Equvalence Class Partitions

✅ BUGA's Dilemma:

"Too many numbers!! Some prime, some no-prime. Me brain hurt! How split them?!" 🤯

Instead of testing infinite numbers, let’s group them into categories using Equivalence Partitioning.

📌 Task: Fill in the Equivalence Partitioning Table

Equivalence ClassExample InputsExpected OutputNotes
E1: Valid Prime Numbers2, 3, 5, 7, 11, ...true
E2: Non-Prime Natural Numbers...?
.........

✍️ Complete the missing parts so BUGA can test smarter, not harder!


🛠 Step 3: Finding the Tricky Edge Cases

Boundary Value Analysis

✅ BUGA's Dilemma:

"Bugs… always hide in corners. Like saber-tooth cats in cave! Me must check dangerous edges." 🦷😨

BUGA needs to test Boundary Values—the critical numbers where bugs might appear.

📌 Task: Fill in the Boundary Value Analysis Table

Boundary ConditionTest InputExpected OutputReasoning
E1 Lower boundary - 11falsethe lower bound of E1 -1
E1 Lower boundary2truethe bound of E1
E1 Lower boundary + 13truethe upper bound of E1
............

✍️ Help BUGA complete this table to catch tricky edge cases!


🛠 Step 4: Writing Unit Tests in JUnit

JUnit Test Cases

✅ BUGA's Dilemma:

"Me must write tests in Java?!" 🪨💻

Now that BUGA understands what to test, he needs to write JUnit tests.

📌 Task: Write the JUnit test cases

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

@Tag("BBT")
class PrimeTest {
@Test
void testPrimeNumbersE1() {
// TODO: Implement test for equivalence partition 1
// given
// when
// then
}

@Test
void testPrimeNumbersBvaE1() {
// TODO: Implement test for boundary values of equivalence partition 1
// given
// when
// then
}
...
}

✍️ Help BUGA write the unit tests for all the identified EP and BVAs!


Congratulations! You have successfully helped BUGA become a Black Box Testing Master! 🎉

🐒 Now go forth and test like a caveman… but smarter! 🦴💻🔥