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

Share:
11,244
Lucan
Author by

Lucan

Updated on June 04, 2022

Comments

  • Lucan
    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
    Lucan almost 11 years
    Okay, 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
    Sankumarsingh almost 11 years
    @Lucan :- I have updated the code for your answer, check the catch statement.
  • Sankumarsingh
    Sankumarsingh almost 11 years
    Hope you have created the log4j.properties file for this.
  • Lucan
    Lucan almost 11 years
    I 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
    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
    Kumrun Nahar Keya over 6 years
    try catch is not the appropriate solution for the above question
  • MandyShaw
    MandyShaw over 5 years
    Hi, since this is a very old question, please edit your answer to explain what it provides that the existing answers don't. Thanks.