Skip to content

Commit a5ca5fe

Browse files
Improved the first paragraph. Removed Exceptions.
1 parent 2109537 commit a5ca5fe

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

rules/S5977/java/rule.adoc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
== Why is this an issue?
22

3-
Randomness in test code, whether introduced intentionally to cover multiple scenarios or unintentionally through non-deterministic library functions, undermines the principles of reliable and effective testing.
4-
In most cases, randomness leads to problems and should be avoided.
5-
6-
Fundamentally, we aim to make tests deterministic and reproducible, primarily for the following reasons:
3+
Randomness in test code, whether introduced intentionally to cover multiple scenarios or unintentionally through non-deterministic library functions, undermines the principles of effective testing.
4+
In most cases, randomness leads to problems, resulting in code that is unreliable and difficult to debug.
5+
Consequently, deterministic and reproducible tests are preferred, primarily for the following reasons:
76

87
* When a test fails, the ability to reproduce the conditions that led to the failure is crucial for effective debugging.
98
Randomness can make it difficult or even impossible to pinpoint the root cause, as subsequent runs may not exhibit the same failure.
@@ -16,10 +15,6 @@ A stable CI pipeline relies on deterministic test outcomes.
1615
1716
This rule raises an issue when ``++new Random()++`` or ``++UUID.randomUUID()++`` are called in test code.
1817

19-
=== Exceptions
20-
21-
This rule excludes the use of library functions that read the system clock (e.g., `++new Date()++`, `++Instant.now()++`, ...).
22-
2318
== How to fix it
2419

2520
* When a test uses random numbers to generate inputs, an easy fix is to replace those random inputs with pseudo-random values generated from a known seed.

0 commit comments

Comments
 (0)