25 lines
754 B
Plaintext
25 lines
754 B
Plaintext
![]() |
There's no reason to use literal boolean values or nulls in assertions. Instead of using them with _assertEquals_, _assertNotEquals_ and similar methods, you should be using _assertTrue_, _assertFalse_, _assertNull_ or _assertNotNull_ instead (or _isNull_ etc. when using Fest). Using them with assertions unrelated to equality (such as _assertNull_) is most likely a bug.
|
||
|
|
||
|
Supported frameworks:
|
||
|
* JUnit3
|
||
|
* JUnit4
|
||
|
* JUnit5
|
||
|
* Fest assert
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
Assert.assertTrue(true); // Noncompliant
|
||
|
assertThat(null).isNull(); // Noncompliant
|
||
|
|
||
|
assertEquals(true, something()); // Noncompliant
|
||
|
assertNotEquals(null, something()); // Noncompliant
|
||
|
----
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
assertTrue(something());
|
||
|
assertNotNull(something());
|
||
|
----
|