Print message on assertTrue either test is Passed or Failed

3,267 views
Skip to first unread message

mahadi hasan

unread,
Sep 17, 2012, 6:50:32 AM9/17/12
to testng...@googlegroups.com
Hi,

Is there is any way to simply print a message on every assertTrue either the test is passed or Failed. Basically i wanted to have a better log in my tests.

Best Regards,
Mahadi

mahadi hasan

unread,
Sep 17, 2012, 11:16:48 AM9/17/12
to testng...@googlegroups.com
Hello again,

I have tried to build a custom function in order to meet my target, i am not sure if it a standard to way to do this, can anybody recommend any other alternative good solution.


public void assertTrue(boolean condition, String comment) {
        if(condition){
            System.out.println("Passed - " +comment);
            Assert.assertTrue(condition, comment);
        }else{
            System.out.println("Error - "+comment  );
            Assert.assertTrue(condition, comment);
        }
    }


Best Regards,
Mahadi

mani kandan

unread,
Sep 17, 2012, 1:22:51 PM9/17/12
to testng...@googlegroups.com
Mahadi, 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/6nQkm0Tk3RQJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.



--
ALWAYS KEEP SMILING

 FOR U EVER,
 
     G.MANIKANDAN

Roman Hiden

unread,
Sep 20, 2012, 12:56:48 PM9/20/12
to testng...@googlegroups.com
you can use FlexibleAsserts class. you have the ability to print before assert after assert etc.

mahadi hasan

unread,
Sep 21, 2012, 4:32:28 PM9/21/12
to testng...@googlegroups.com
Hi Roman,

I really dont have any idea about FlexibleAsserts class, would you please explain a little bit more how to use that.

Best Regards,
Mahadi

Cédric Beust ♔

unread,
Sep 21, 2012, 4:41:54 PM9/21/12
to testng...@googlegroups.com
The class is org.testng.asserts.Assertion (TestNG 6.8 only).

-- 
Cédric




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/yXa8feQEYJgJ.

Roman Hiden

unread,
Sep 26, 2012, 2:41:42 PM9/26/12
to testng...@googlegroups.com
@Test
public class A {
  private FlexibleAssert m_assert = new FlexibleAssert();

  public void test1() {
    m_assert.assertTrue(true, "test1()");
  }
}
For example, here is what a class that logs each assert would look like:

public class LoggingAssert extends FlexibleAssert {

  private List<String> m_messages = Lists.newArrayList();

  @Override
  public void onBeforeAssert(IAssert a) {
    m_messages.add("Test:" + a.getMessage());
  }

  public List<String> getMessages() {
    return m_messages;
  }
}
  -- The above is code wrote Cedric in the following thread that you might want to read
https://groups.google.com/forum/?fromgroups=#!topic/testng-users/Q5KGi30f0FE

 
Reply all
Reply to author
Forward
0 new messages