vidstige
vidstige

Reputation: 13079

Ignoring method in TestNG assert messages

When a test fails with an assert in a TestNG test method it outputs a message containing the method name like so

MyTestFixture:49->when_clicking_x_y_happens:49 expected:<Foo...> but was:<Bar...>

So far all is good. However, when having asserts in another method than the test method it displays a weird message:

MyTestFixture:49->TestHelper.verifyXYZwasDisplayed:49 expected:<Foo...> but was:<Bar...>

Here the verifyXYZwasDisplayed from the TestHelper class is displayed in the message. It would be more helpful if the message contained the test method name instead. Can I somehow annotate this method be ignore when TestNG creates the assert message?

Upvotes: 0

Views: 189

Answers (1)

fge
fge

Reputation: 121710

I guess your TestHelper.verifyXYZwasDisplayed() method has an assert*() in it. Which means the AssertionError thrown will point at the line where this assertion is used.

Instead, make it return a boolean which is true if the condition is met, then use:

assertTrue(TestHelper.verifyXYZwasDisplayed(blah));

Upvotes: 1

Related Questions