What problem are you trying to solve?
Test code readability.
In a test case:
assertTrue(true) is a no-op
assertTrue(false) can be replaced with fail()
Similar for assertFalse, etc. The same logic could probably be done in several variants for various test frameworks.
Describe the situation before applying the recipe
@Test
void testExceptionThrown() {
try {
someOperationWith("Invalid argument");
fail("Expected exception was not thrown");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
Describe the situation after applying the recipe
@Test
void testExceptionThrown() {
try {
someOperationWith("Invalid argument");
fail("Expected exception was not thrown");
} catch (IllegalArgumentException e) {
}
}
Any additional context
I've stumbled upon this pattern when providing OSS examples for
What problem are you trying to solve?
Test code readability.
In a test case:
assertTrue(true)is a no-opassertTrue(false)can be replaced withfail()Similar for
assertFalse, etc. The same logic could probably be done in several variants for various test frameworks.Describe the situation before applying the recipe
Describe the situation after applying the recipe
Any additional context
I've stumbled upon this pattern when providing OSS examples for
@Test(expected=Exception.class)as opposed to explicit try-catch #761.