0
0
JUnittesting~5 mins

Deterministic tests in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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 input and environment, ensuring reliability and predictability.
Click to reveal answer
beginner
Why are deterministic tests important in software testing?
They help identify real bugs by avoiding false failures caused by randomness or external factors, making debugging easier and builds more stable.
Click to reveal answer
intermediate
How can you make a test deterministic when it involves random data?
Use a fixed seed for random number generators so the sequence of random values is the same every time the test runs.
Click to reveal answer
intermediate
In JUnit, what practice helps ensure tests are deterministic when dealing with time-dependent code?
Mock or control the system clock or time source so the test always uses a fixed, known time.
Click to reveal answer
beginner
What is a common cause of non-deterministic tests?
Tests that depend on external systems, network, or shared state without isolation can behave differently each run.
Click to reveal answer
What characteristic defines a deterministic test?
ADepends on external services
BRuns faster than other tests
CUses random data every time
DAlways produces the same result given the same input
How can you control randomness in a JUnit test to make it deterministic?
AAvoid assertions
BRun the test multiple times
CUse a fixed seed for the random number generator
DUse external APIs
Which of the following can cause a test to be non-deterministic?
ARelying on current system time without control
BUsing a fixed system clock
CMocking external dependencies
DSetting fixed input data
Why should tests avoid depending on external systems?
ATo reduce test execution time
BTo ensure tests are deterministic and reliable
CTo increase code complexity
DTo use more network bandwidth
What is a good practice to make time-dependent tests deterministic in JUnit?
AMock the system clock to return a fixed time
BUse Thread.sleep() to wait
CRun tests only at night
DIgnore time in assertions
Explain what deterministic tests are and why they matter in software testing.
Think about tests giving the same result every time.
You got /3 concepts.
    Describe strategies to make tests deterministic when they involve randomness or time.
    Consider how to control variables that change each run.
    You got /3 concepts.