Bird
Raised Fist0
Testing Fundamentalstesting~20 mins

Why white-box testing examines code internals in Testing Fundamentals - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
White-Box Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of White-Box Testing
Why does white-box testing focus on examining the internal code structure?
ATo understand and test the internal logic and paths of the code
BTo verify the software's external behavior without looking at the code
CTo check the software's user interface for usability issues
DTo test the software only through its user inputs and outputs
Attempts:
2 left
💡 Hint
Think about what 'white-box' means compared to 'black-box' testing.
🧠 Conceptual
intermediate
2:00remaining
White-Box Testing Benefits
Which benefit is unique to white-box testing compared to black-box testing?
ATesting the software without knowing its internal code
BTesting the software only through its user interface
CChecking if the software meets user requirements
DFinding hidden errors by analyzing code branches and conditions
Attempts:
2 left
💡 Hint
Consider what white-box testing can do that black-box testing cannot.
❓ Predict Output
advanced
2:00remaining
Output of White-Box Test Coverage Code
What is the output of this white-box test coverage code snippet?
Testing Fundamentals
def test_function(x):
    if x > 0:
        return 'Positive'
    elif x == 0:
        return 'Zero'
    else:
        return 'Negative'

results = [test_function(i) for i in [-1, 0, 1]]
print(results)
A['Zero', 'Positive', 'Negative']
B['Negative', 'Zero', 'Positive']
C['Positive', 'Zero', 'Negative']
D['Negative', 'Positive', 'Zero']
Attempts:
2 left
💡 Hint
Trace the function calls for each input in the list [-1, 0, 1].
❓ assertion
advanced
2:00remaining
Correct Assertion for White-Box Test
Which assertion correctly verifies that a function covers all branches in white-box testing?
Testing Fundamentals
def classify_number(n):
    if n > 0:
        return 'pos'
    elif n == 0:
        return 'zero'
    else:
        return 'neg'
Aassert classify_number(1) == 'pos' or classify_number(0) == 'zero' or classify_number(-1) == 'neg'
Bassert classify_number(1) == 'neg' and classify_number(0) == 'zero' and classify_number(-1) == 'pos'
Cassert classify_number(1) == 'pos' and classify_number(0) == 'zero' and classify_number(-1) == 'neg'
Dassert classify_number(1) == 'pos' and classify_number(0) == 'pos' and classify_number(-1) == 'pos'
Attempts:
2 left
💡 Hint
All branches must be tested and verified correctly.
🔧 Debug
expert
2:00remaining
Debugging White-Box Test Failure
A white-box test fails because a branch is never executed. What is the most likely cause?
AThe test inputs do not cover all possible code paths
BThe software has no bugs and the test is incorrect
CThe test only checks the user interface, ignoring code
DThe software is tested only with invalid inputs
Attempts:
2 left
💡 Hint
Think about what white-box testing requires to cover all branches.

Practice

(1/5)
1. Why does white-box testing focus on examining the internal code of a program?
easy
A. To verify the program's performance under load
B. To check the program's user interface for usability
C. To test the program without knowing its internal workings
D. To understand the program's structure and test specific code paths

Solution

  1. Step 1: Understand white-box testing purpose

    White-box testing involves looking inside the code to test its logic and paths.
  2. Step 2: Compare options with testing goals

    Only To understand the program's structure and test specific code paths matches the goal of testing internal code structure and paths.
  3. Final Answer:

    To understand the program's structure and test specific code paths -> Option D
  4. Quick Check:

    White-box tests code internals = D [OK]
Hint: White-box tests code internals, not UI or performance [OK]
Common Mistakes:
  • Confusing white-box with black-box testing
  • Thinking white-box tests UI or performance
  • Ignoring the code structure in white-box testing
2. Which of the following is the correct syntax to write a white-box test case in Python using the unittest framework?
easy
A. class TestFunction(unittest.TestCase): def test_case(self): self.assertEqual(function_to_test(), expected_value)
B. def test_function(): assert function_to_test() == expected_value
C. function test_function() { expect(function_to_test()).toBe(expected_value); }
D. function_to_test() == expected_value

Solution

  1. Step 1: Identify Python unittest syntax

    Python unittest requires a class inheriting unittest.TestCase and methods starting with test_.
  2. Step 2: Match options to unittest style

    class TestFunction(unittest.TestCase): def test_case(self): self.assertEqual(function_to_test(), expected_value) correctly defines a test class and method using self.assertEqual.
  3. Final Answer:

    class TestFunction(unittest.TestCase): def test_case(self): self.assertEqual(function_to_test(), expected_value) -> Option A
  4. Quick Check:

    Python unittest uses classes and assertEqual [OK]
Hint: Python unittest tests use classes and assertEqual method [OK]
Common Mistakes:
  • Using plain functions without unittest class
  • Confusing JavaScript or XML syntax with Python
  • Missing self parameter in test methods
3. Consider this Python function and its white-box test case:
def is_even(n):
    if n % 2 == 0:
        return True
    else:
        return False

# Test case
assert is_even(3) == False
assert is_even(4) == True
What is the result of running this test case?
medium
A. First assertion fails, second passes
B. Both assertions fail
C. Both assertions pass, test succeeds
D. Syntax error in test case

Solution

  1. Step 1: Evaluate is_even(3)

    3 % 2 is 1, so function returns False, matching assert is_even(3) == False.
  2. Step 2: Evaluate is_even(4)

    4 % 2 is 0, so function returns True, matching assert is_even(4) == True.
  3. Final Answer:

    Both assertions pass, test succeeds -> Option C
  4. Quick Check:

    3 odd = False, 4 even = True [OK]
Hint: Check function output matches assertion values exactly [OK]
Common Mistakes:
  • Assuming 3 is even
  • Confusing modulus operator result
  • Thinking assert causes syntax error
4. A white-box test case for a function has this code:
def calculate_discount(price):
    if price > 100:
        return price * 0.9
    else:
        return price * 0.95

# Test
assert calculate_discount(100) == 90
What is the problem with this test?
medium
A. The test expects wrong discount for price 100
B. The function has a syntax error
C. The test should use assertEqual instead of assert
D. The function does not handle negative prices

Solution

  1. Step 1: Analyze function logic for price 100

    Price 100 is not greater than 100, so else branch applies: 100 * 0.95 = 95.
  2. Step 2: Compare test assertion value

    Test expects 90, but function returns 95, so assertion fails.
  3. Final Answer:

    The test expects wrong discount for price 100 -> Option A
  4. Quick Check:

    Price 100 gets 5% discount, test expects 10% [OK]
Hint: Check boundary conditions carefully in tests [OK]
Common Mistakes:
  • Assuming price 100 triggers > 100 condition
  • Thinking assert is invalid in Python
  • Ignoring else branch logic
5. You want to write white-box tests to cover all branches of this function:
def classify_number(x):
    if x > 0:
        if x % 2 == 0:
            return 'Positive even'
        else:
            return 'Positive odd'
    elif x < 0:
        return 'Negative'
    else:
        return 'Zero'
Which set of test inputs covers all branches?
hard
A. [2, 4, 6]
B. [1, 2, 0, -1]
C. [0, -5]
D. [-1, 0, 1]

Solution

  1. Step 1: Identify branches to cover

    Branches: x > 0 with even and odd, x < 0, and x == 0.
  2. Step 2: Check test inputs for coverage

    Input 1 covers positive odd, 2 covers positive even, 0 covers zero, -1 covers negative.
  3. Final Answer:

    [1, 2, 0, -1] -> Option B
  4. Quick Check:

    All branches tested by these inputs [OK]
Hint: Test positive even, positive odd, zero, and negative separately [OK]
Common Mistakes:
  • Missing positive odd or even cases
  • Not testing zero case
  • Assuming fewer inputs cover all branches
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard