Another method provided by TestCase is void assertTrue(String failResponse, boolean result). This is a simplified version of assertEquals(...) used when the result can be expressed as a boolean true or false. Note that any test using assertTrue can also be written as assertEquals(failResponse, result, true). For instance we could write another test method to test the myMethod2() method of MyClass. The test class now has two test methods and JUnit will run both ot them when we click on "Test Current Document." Here, the second test method passes as shown in green below. The frst method still fails and its error messages are still shown. Clicking on the error message will highlight the line where the error occured. Correcting the code in myMethod1(...) would result in all the test methods being listed in green with no error messages.
Available under Creative Commons-ShareAlike 4.0 International License. Download for free at http://email@example.com
Figure 7.4 Using assertTrue(...)in a test method
assertTrue(...) is used in test_myMethod2(...) above and does not generate an error because it is executed with a boolean true value.