Error messages in assert statements

20 views
Skip to first unread message

Andreas Guther

unread,
Mar 30, 2006, 2:43:45 PM3/30/06
to testng...@googlegroups.com
I noticed that the error message from the Assert methods are either the error message as passed in or if no third argument is passed in, it shows the expected and actual value.

What I liked from JUnit is that Junit is concatenating my error message and the expected/actual message.

TestNG Example:
==================
Assert.assertEquals(order, elementOrder[counter], "Problems with Order number");
prints
java.lang.AssertionError: Problems with Order number
    at org.testng.Assert.fail (Assert.java:73)

Assert.assertEquals(order, elementOrder[counter]);
prints
java.lang.AssertionError: expected:<50> but was:<0>
    at org.testng.Assert.fail(Assert.java:73)

I know I can do something like the following:
Assert.assertEquals(order, elementOrder[counter], "Problems with Order number.  Expected " + elementOrder[counter] + " but found " + order);
so it prints
java.lang.AssertionError: Problems with Order number.  Expected 50 but found 0
    at org.testng.Assert.fail(Assert.java:73)

It would be very convenient if the TestNG framework could do that for me as JUnit does it.

Andreas

Cédric Beust ♔

unread,
Mar 30, 2006, 3:16:48 PM3/30/06
to testng...@googlegroups.com
Indeed, Andreas.  I'll look into that.

--
Cédric

Alexandru Popescu

unread,
Mar 31, 2006, 3:16:01 AM3/31/06
to testng...@googlegroups.com
Fixing this now.

./alex
--
.w( the_mindstorm )p.

#: Cédric Beust ♔ changed the world a bit at a time by saying (astral date: 3/30/2006 11:16 PM) :#

Alexandru Popescu

unread,
Mar 31, 2006, 3:21:00 AM3/31/06
to testng...@googlegroups.com
Should be fixed in CVS head.

./alex
--
.w( the_mindstorm )p.

#: Cédric Beust ♔ changed the world a bit at a time by saying (astral date: 3/30/2006 11:16 PM) :#

Andreas Guther

unread,
Mar 31, 2006, 9:36:35 AM3/31/06
to testng...@googlegroups.com
I created an Jira entry:

http://jira.opensymphony.com/browse/TESTNG-57

Andreas


On 3/31/06, Andreas Guther <a.gu...@guther.com> wrote:

Andreas

Alexandru Popescu

unread,
Mar 31, 2006, 1:33:01 PM3/31/06
to testng...@googlegroups.com
#: Andreas Guther changed the world a bit at a time by saying (astral date: 3/31/2006 5:36 PM) :#

> I created an Jira entry:
>
> http://jira.opensymphony.com/browse/TESTNG-57
>
> Andreas
>
>

Andreas I am wondering if you tested the CVS Head before creating the jira issue? (so I can
understand if the issue is about the current CVS HEAD or is it about your previous request).

TIA,

Andreas Guther

unread,
Mar 31, 2006, 1:39:26 PM3/31/06
to testng...@googlegroups.com
Alexandru,

I did not test the CVS head.  I might have misunderstood your statement in that way that I thought you were planning to do the fix.  But now I believe you fixed it already.

I added the Jira entry because in my firsts email I was not sure if the described behavior was by design or a bug.  Once I got the following emails I thought it might be helpful to have it as a Jira entry.

I guess I just did not expect that it would be fixed within less than 24 hours :)

>> > >> Assert.assertEquals (order, elementOrder[counter]);

Alexandru Popescu

unread,
Mar 31, 2006, 2:01:04 PM3/31/06
to testng...@googlegroups.com
Thanks for details. Can you try out the CVS Head and let us know if it works for you?

tia,

./alex
--
.w( the_mindstorm )p.

#: Andreas Guther changed the world a bit at a time by saying (astral date: 3/31/2006 9:39 PM) :#

>> >> > >> Assert.assertEquals(order, elementOrder[counter]);

Andreas Guther

unread,
Mar 31, 2006, 2:48:51 PM3/31/06
to testng...@googlegroups.com
Alexandru,

I checked out the head and run the mvn package goal. I get two SNAPSHOT jar files:
testng-4.7-SNAPSHOT.jar and testng-4.7-SNAPSHOT-jdk15.jar.  Isthe first one the JDK 1.4 version?

I need to run it on JDK 1.4 though I can and did build it with JDK 5.

Cédric Beust ♔

unread,
Mar 31, 2006, 2:52:06 PM3/31/06
to testng...@googlegroups.com
Uh, Maven works on our depot?  :-)

Just build with "ant", this will give you 2 jar files.

--
Cedric
--
Cédric

Andreas Guther

unread,
Mar 31, 2006, 3:13:44 PM3/31/06
to testng...@googlegroups.com
In one word: WORKS
In two words: Thank You!

How did I test?

I got the two jar files using ant.  I put them on our local Maven 2 repository, added the new version to my pom.xml, then run the mvn idea:idea goal and had IntelliJ reload the generated project file.  Then I changed one test to generate a failure and the output is as expected:

java.lang.AssertionError: Answer does not match! expected:<Answer 4> but was:<Answer 1>
    at org.testng.Assert.fail(Assert.java:74)
    at org.testng.Assert.failNotEquals(Assert.java:346)
    at org.testng.Assert.assertEquals(Assert.java:95)
    at org.testng.Assert.assertEquals(Assert.java:110)

Excellent reponse time in fixing the bug!!!!

My M2 dependency entry:

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <!--
            <version>4.6.1</version>
            -->
            <version> 4.7beta</version>
            <scope>test</scope>
            <classifier>jdk14</classifier>
        </dependency>

Alexandru Popescu

unread,
Mar 31, 2006, 3:55:45 PM3/31/06
to testng...@googlegroups.com
Thanks for confirmation.

./alex
--
.w( the_mindstorm )p.

Reply all
Reply to author
Forward
0 new messages