Catch block Assertion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Catch block Assertion

Sanju
Hi all,
Could you please clarify the below one?

Sample method
----------------------
public int methodname(int a, int b, SoftAssert sassert) throws Exception
{
try
{
int sum = a+b;     
}
catch(Throwable e)
{
sassert.assertTrue(false, "Error Occured" + e.toString());
}
return sum;
}

If I write method like this in my project, eventhough there is a exception, catch block assert statement is not getting executed, however If I put any print statement in catch block, it is getting executed.
Please clarify if I need to correct any.

Thank You!



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Catch block Assertion

Krishnan Mahadevan

You are working with a SoftAssert object. For the assertions to be triggered, you need to invoke assertAll() method.

SoftAssert is built to assert everything but fail at the end (by invoking assertAll())

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply-To: <[hidden email]>
Date: Saturday, March 3, 2018 at 7:28 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Catch block Assertion

 

Hi all,

Could you please clarify the below one?

 

Sample method

----------------------

public int methodname(int a, int b, SoftAssert sassert) throws Exception

{

try

{

int sum = a+b;       

}

catch(Throwable e)

{

sassert.assertTrue(false, "Error Occured" + e.toString());

}

return sum;

}

 

If I write method like this in my project, eventhough there is a exception, catch block assert statement is not getting executed, however If I put any print statement in catch block, it is getting executed.

Please clarify if I need to correct any.

 

Thank You!

 

 

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Catch block Assertion

Sanju
Thank You  Krishnan for the reply.

Below method I'm calling in my @test class where I'm giving assertAll() at the end.


On Sat, Mar 3, 2018 at 4:18 AM, Krishnan Mahadevan <[hidden email]> wrote:

You are working with a SoftAssert object. For the assertions to be triggered, you need to invoke assertAll() method.

SoftAssert is built to assert everything but fail at the end (by invoking assertAll())

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Reply-To: <[hidden email]>
Date: Saturday, March 3, 2018 at 7:28 AM
To: testng-users <[hidden email]>
Subject: [testng-users] Catch block Assertion

 

Hi all,

Could you please clarify the below one?

 

Sample method

----------------------

public int methodname(int a, int b, SoftAssert sassert) throws Exception

{

try

{

int sum = a+b;       

}

catch(Throwable e)

{

sassert.assertTrue(false, "Error Occured" + e.toString());

}

return sum;

}

 

If I write method like this in my project, eventhough there is a exception, catch block assert statement is not getting executed, however If I put any print statement in catch block, it is getting executed.

Please clarify if I need to correct any.

 

Thank You!

 

 

 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[hidden email].
To post to this group, send email to
[hidden email].
Visit this group at
https://groups.google.com/group/testng-users.
For more options, visit
https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/qz3dLfYOTMA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.