Recall & Review
beginner
What does it mean for a test to be deterministic?
A deterministic test always produces the same result when run with the same code and inputs, no matter how many times it runs.
Click to reveal answer
beginner
Why are deterministic tests important in software testing?
They help ensure reliability and trust in test results because failures are consistent and reproducible, making debugging easier.
Click to reveal answer
intermediate
How can randomness affect test determinism?
Randomness can cause tests to behave differently each run, leading to flaky tests that sometimes pass and sometimes fail.
Click to reveal answer
intermediate
What is a common way to make tests deterministic when they use random values?
Set a fixed seed for the random number generator so it produces the same sequence of values every time the test runs.
Click to reveal answer
beginner
Example: In pytest, how do you fix randomness to make a test deterministic?
Use code like <code>import random
random.seed(42)</code> at the start of your test to fix the random seed.Click to reveal answer
What is a key characteristic of a deterministic test?
✗ Incorrect
Deterministic tests always produce the same result with the same inputs, ensuring reliability.
Which practice helps make tests deterministic when randomness is involved?
✗ Incorrect
Setting a fixed seed ensures the random values are the same every run, making tests deterministic.
What problem do non-deterministic (flaky) tests cause?
✗ Incorrect
Flaky tests fail unpredictably, making it hard to know if a failure is real or random.
In pytest, where should you set the random seed to ensure determinism?
✗ Incorrect
Setting the seed inside the test ensures the random values are predictable for that test run.
Which of these is NOT a cause of non-deterministic tests?
✗ Incorrect
Using fixed inputs and no randomness helps keep tests deterministic.
Explain what deterministic tests are and why they matter in software testing.
Think about how tests behave when run multiple times with the same code.
You got /3 concepts.
Describe how you would make a pytest test deterministic if it uses random numbers.
Consider the random.seed() function and its placement.
You got /3 concepts.