Where the assert message will be displayed
11,244
Refer the site for more info: http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertTrue(java.lang.String, boolean)
public static void assertTrue(java.lang.String message, boolean condition)
Asserts that a condition is true. If it isn't it throws an AssertionError with the given message.
Parameters:
message
- the identifying message for the AssertionError (null okay)
condition
- condition to be checked
Author by
Lucan
Updated on June 04, 2022Comments
-
Lucan about 2 years
I tried the code
package Base; import org.testng.Assert; import org.testng.annotations.Test; public class Assertcheck { @Test public void check() { Assert.assertTrue(true, "testing the string true"); } }
and the code succeeds but the message "testing the string true" is not displayed. i checked in console output and also in testNG results.
-
Lucan almost 11 yearsOkay, thank you and i am using log4j. now could you tell me how to print this message in it only if the condition fails or suggest me any material for this
-
Sankumarsingh almost 11 years@Lucan :- I have updated the code for your answer, check the catch statement.
-
Sankumarsingh almost 11 yearsHope you have created the log4j.properties file for this.
-
Lucan almost 11 yearsI am using keyword hybrid framework and am asserting some values and even-though the assert fails the testng says it succeeds. how to solve this?
-
Sankumarsingh almost 11 years@Lucan: When you are using TestNG, do not use try catch for Assert statements. In that case, if Assert fails, TestNG will show the error. Basically what happens in your case, if Assert failed, it throw an exception and this exception is handled by the catch statement, so in both case whether exception occurs or not, you have a defined rule. So for testNG both become expected. Remove the try-Catch statement and let me know its working or not.
-
Kumrun Nahar Keya over 6 yearstry catch is not the appropriate solution for the above question
-
MandyShaw over 5 yearsHi, since this is a very old question, please edit your answer to explain what it provides that the existing answers don't. Thanks.