It means you randomly select input values from the input domain to create test cases, rather than carefully designing them based on specific rules or coverage goals.

Why random choice?

Because in many real-world programs:

  • The input space is huge or even infinite
  • We can’t test everything exhaustively
  • We might not know where bugs are hiding

So we just pick inputs at random, hoping to hit unexpected or edge cases.

When not to use random choice

Attention

Random testing does not guarantee of branch coverage.

You only use random choice test design for linear programs. It means a program with straight-line logic - i.e. no branches, no loops, no conditions, just simple computation from input to output. Consider the below example:

def rate_discount(age):
    if age < 18:
        return "Child discount"
    elif age < 65:
        return "Adult rate"
    else:
        return "Senior discount"

Why not use random testing here? Random values may miss critical paths, there might be low probability of hitting edge cases. Example: What if your random values never generate age >= 65? Then the "Senior discount" branch is never tested.

Example

Let’s say you’re testing this function:

def is_even(n: int) -> bool:
    return n % 2 == 0

Instead of designing tests like:

  • is_even(2), is_even(3), is_even(0), etc.

You can generate random test cases like:

import random
 
for _ in range(10):
    x = random.randint(-1000, 1000)
    print(f"Test input: {x}, Output: {is_even(x)}")

You’re choosing test values randomly from a large range, to see if the function breaks anywhere.


Back to parent page: Software Testing

Web_and_App_Development Software_Testing Software_Validation SOFT3202 Blackbox_Testing Functional_Testing Randon_Value_Test_Design