Multiple assertions in single test

620 views
Skip to first unread message

basu

unread,
May 28, 2008, 1:11:42 AM5/28/08
to testng-users
Hi,
I have many scenarios, in which i need to perform multiple
verifications in a single test.one such example is after clicking some
link, i need to verify URL as well as the header displayed are
proper.Any one of the assertion failure will raise the exception and
skips the remaining code.I just want to know is there any method which
will perform verification and continue with the remaining code even
after verification is failed.
Could you plz ,let me know your inputs.

Regards
-B

Cédric Beust ♔

unread,
May 28, 2008, 1:15:16 AM5/28/08
to testng...@googlegroups.com
This is not possible with asserts, but you can easily simulate it:  accumulate the results of your tests in boolean variables and at the end of the method, assert that they are all true.

--
Cedric
--
Cédric

basu

unread,
May 28, 2008, 1:43:01 AM5/28/08
to testng-users
Hi Cedric,
In the Annotation type Test class (http://testng.org/javadocs/org/
testng/annotations/Test.html) , a method call sequential is available
i tried using the same , i am not able to get the required
output.Could you please tell me how to use the same.

Cédric Beust ♔ wrote:
> This is not possible with asserts, but you can easily simulate it:
> accumulate the results of your tests in boolean variables and at the end of
> the method, assert that they are all true.
>
> --
> Cedric
>
>
> On Tue, May 27, 2008 at 10:11 PM, basu <bas....@gmail.com> wrote:
>
> Hi,
> I have many scenarios, in which i need to perform multiple
> verifications in a single test.one such example is after clicking some
> link, i need to verify URL as well as the header displayed are
> proper.Any one of the asseHirtion failure will raise the exception and
> skips the remaining code.I just want to know is there any method which
> will perform verification and continue with the remaining code even
> after verification is failed.
> Could you plz ,let me know your inputs.
>
> Regards
> -B
>
>
>
>
> --
> C�dric

Cédric Beust ♔

unread,
May 28, 2008, 1:54:38 AM5/28/08
to testng...@googlegroups.com
This attribute is only meaningful when you are running your tests in parallel, which doesn't seem to be your case.

--
Cedric
--
Cédric

Steve Loughran

unread,
May 28, 2008, 6:32:17 AM5/28/08
to testng...@googlegroups.com
On Wed, May 28, 2008 at 6:15 AM, Cédric Beust ♔ <cbe...@google.com> wrote:
> This is not possible with asserts, but you can easily simulate it:
> accumulate the results of your tests in boolean variables and at the end of
> the method, assert that they are all true.

This could be factored out into a reusable AssertionSet class, perhaps


AssertionSet as=new AssertionSet();

as.assertTrue(.... )
as.assertFalse(....)

as.checkAssertions()

each assert in the set would, if failing, create an exception (and
stack trace) and record that with the string in a list of
failedAsserts. Then the final checkAssertions() method would, if the
asserts list were non empty, print everything out then throw an
overall assert (maybe one that nests all the others)

Thomas Johnson

unread,
May 28, 2008, 7:34:40 AM5/28/08
to testng...@googlegroups.com
Going with the AssertionSet idea, why not set it up as a DataProvider
as well? You could then feed all of the recorded assertions to a test
method that verifies or calls the assertion. You'd get a decent record
of all the results that way.

Alternatively, you could set up all your tests to write to class
variables and then have a whole slew of other tests performing
assertions on the values that you've stored.

Cédric Beust ♔

unread,
May 28, 2008, 12:32:10 PM5/28/08
to testng...@googlegroups.com
That's a neat idea, Steve, and probably worth including in the distribution.

--
Cedric
--
Cédric

Steve Loughran

unread,
May 28, 2008, 5:17:02 PM5/28/08
to testng...@googlegroups.com
On Wed, May 28, 2008 at 5:32 PM, Cédric Beust ♔ <cbe...@google.com> wrote:
> That's a neat idea, Steve, and probably worth including in the distribution.
>

If you do it, the exception thrown at the end should be able to
contain all the exceptions/assertions raised, so that the right
reporting tools and formats can handle the lot of them. Selenium can
generate multiple results from a single test case already.

-steve

Dan Fabulich

unread,
May 29, 2008, 4:30:29 AM5/29/08
to testng...@googlegroups.com

Then maybe we should submit my patch for it, don't you think? :-)

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

-Dan

Reply all
Reply to author
Forward
0 new messages