Getting Status of Test Method (either pass or fail)......

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

Getting Status of Test Method (either pass or fail)......

Manjunath Bellur
Hi All,
 Is there a way to get the status of a test method (either pass or fail) in TestNG. Let me explain why I require this, with an example.

I have created a suite file to test two classes

Class 1: Verifies some value in a page.  
     1) User Logs into a Portal
     2) Opens up some page (say Page1) to verify some value
     3) If the Value is not present (the testcase fails)
     4) If the value is present User logs off and goes back to login screen.

Class 2:
      1) User Logs into a portal
      2) Opens up another page (say Page2) to verify some value
      3) If the value is not present (testcase fails)
      4) If the value is present User Logs off and goes back to login screen

Now let us assume Method in Class 1 failed (the value is not present) the user is in Page1.
 
So when the method in Class 2 has to run it expects the application to be in Login screen. So my login in Class 2 fails.

One solution I can think of handling this situation, is to get the state of the testcase of Class 1. (either pass or fail) in some method written in Class 1 and click on "Log Off" link.  Just like Exception handling.

This would bring the application to the state which Class 2 expects.

Please tell me whether my approach would be right or is there an easy way to handle this scenario in TestNG.

Please let me know if you need any more information on the problem mentioned above. Helping this would be much appreciated.

Thanks and Regards,
Manjunath
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Getting Status of Test Method (either pass or fail)......

Alexandru Popescu ☀

On 4/11/07, Manjunath Bellur <[hidden email]> wrote:

> Hi All,
>  Is there a way to get the status of a test method (either pass or fail) in
> TestNG. Let me explain why I require this, with an example.
>
> I have created a suite file to test two classes
>
> Class 1: Verifies some value in a page.
>      1) User Logs into a Portal
>      2) Opens up some page (say Page1) to verify some value
>      3) If the Value is not present (the testcase fails)
>      4) If the value is present User logs off and goes back to login screen.
>
> Class 2:
>       1) User Logs into a portal
>       2) Opens up another page (say Page2) to verify some value
>       3) If the value is not present (testcase fails)
>       4) If the value is present User Logs off and goes back to login screen
>
> Now let us assume Method in Class 1 failed (the value is not present) the
> user is in Page1.
>
> So when the method in Class 2 has to run it expects the application to be in
> Login screen. So my login in Class 2 fails.
>
> One solution I can think of handling this situation, is to get the state of
> the testcase of Class 1. (either pass or fail) in some method written in
> Class 1 and click on "Log Off" link.  Just like Exception handling.
>
> This would bring the application to the state which Class 2 expects.
>
> Please tell me whether my approach would be right or is there an easy way to
> handle this scenario in TestNG.
>

Manjunath, after reading your test description the first thing that
occured to me is: a couple of steps look to be configuration-like
steps. I would perform these steps in configuration methods:

Login/Logout: @BeforeX/@AfterX(alwaysRun=true)

(you must decide at what level you want this to be run and around what
code - if it is expensive then you should raise it to test or group or
even suite level).

Then you do some more preparing: move to page N (hey, I would do this
with a @BeforeClass/@BeforeMethod)... and last the test.

So, finally my tests would look like:

@BeforeTest or @BeforeGroup
- login (if it fails nothing that follows will be run, but reported as skipped)

----
Class A:

@BeforeClass or @BeforeMethod
- go to page A

@Test
- do my test

Class B:

@BeforeClass or @BeforeMethod

@Test
- do my test

----
@AfterTest or @AfterGroup with alwaysRun=true -- this will assure that
other groups or tests will start from a well known status (logout).

- logout.

Hope this helps,

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator




> Please let me know if you need any more information on the problem mentioned
> above. Helping this would be much appreciated.
>
> Thanks and Regards,
> Manjunath
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Getting Status of Test Method (either pass or fail)......

Manjunath Bellur
Hey Alex,
    This is cool. I would be using @AfterClass so that each class after it exist makes sure that it is bringing the application to the base state (i.e., Login screen). This was very much helpful. Thanks again.

Thanks and Regards,
Manjunath

On 4/11/07, Alexandru Popescu ☀ <[hidden email]> wrote:

On 4/11/07, Manjunath Bellur <[hidden email]> wrote:
> Hi All,
>  Is there a way to get the status of a test method (either pass or fail) in
> TestNG. Let me explain why I require this, with an example.
>
> I have created a suite file to test two classes

>
> Class 1: Verifies some value in a page.
>      1) User Logs into a Portal
>      2) Opens up some page (say Page1) to verify some value
>      3) If the Value is not present (the testcase fails)
>      4) If the value is present User logs off and goes back to login screen.
>
> Class 2:
>       1) User Logs into a portal
>       2) Opens up another page (say Page2) to verify some value
>       3) If the value is not present (testcase fails)
>       4) If the value is present User Logs off and goes back to login screen
>
> Now let us assume Method in Class 1 failed (the value is not present) the
> user is in Page1.
>
> So when the method in Class 2 has to run it expects the application to be in
> Login screen. So my login in Class 2 fails.
>
> One solution I can think of handling this situation, is to get the state of
> the testcase of Class 1. (either pass or fail) in some method written in
> Class 1 and click on "Log Off" link.  Just like Exception handling.
>
> This would bring the application to the state which Class 2 expects.
>
> Please tell me whether my approach would be right or is there an easy way to
> handle this scenario in TestNG.
>

Manjunath, after reading your test description the first thing that
occured to me is: a couple of steps look to be configuration-like
steps. I would perform these steps in configuration methods:

Login/Logout: @BeforeX/@AfterX(alwaysRun=true)

(you must decide at what level you want this to be run and around what
code - if it is expensive then you should raise it to test or group or
even suite level).

Then you do some more preparing: move to page N (hey, I would do this
with a @BeforeClass/@BeforeMethod)... and last the test.

So, finally my tests would look like:

@BeforeTest or @BeforeGroup
- login (if it fails nothing that follows will be run, but reported as skipped)

----
Class A:

@BeforeClass or @BeforeMethod
- go to page A

@Test
- do my test

Class B:

@BeforeClass or @BeforeMethod

@Test
- do my test

----
@AfterTest or @AfterGroup with alwaysRun=true -- this will assure that
other groups or tests will start from a well known status (logout).

- logout.

Hope this helps,

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator




> Please let me know if you need any more information on the problem mentioned
> above. Helping this would be much appreciated.
>
> Thanks and Regards,
> Manjunath
>  >
>





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Getting Status of Test Method (either pass or fail)......

Alexandru Popescu ☀
On 4/11/07, Manjunath Bellur <[hidden email]> wrote:
> Hey Alex,
>     This is cool. I would be using @AfterClass so that each class after it
> exist makes sure that it is bringing the application to the base state
> (i.e., Login screen). This was very much helpful. Thanks again.
>

The way you group these tests is quite important imo. Remember TestNG
is not just an unit testing framework, so sometimes it may make sense
to organize your tests differently according to what type of testing
you are doing (functional, integration, etc.). That's the reason I
have mentioned groups or test level.

[shameless plug]
At QCon, me and Cedric have presented a couple of strategies for
grouping tests. [1] These strategies will also be described in the
upcoming book authored by Cedric and Hani.

[1] http://qcon.infoq.com/qcon/tracks/show_track.jsp?trackOID=37: Next
Generation Testing with TestNG
[/end-plug]


./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator

> Thanks and Regards,
> Manjunath
>
>
> On 4/11/07, Alexandru Popescu ☀
> <[hidden email] > wrote:
> >
> > On 4/11/07, Manjunath Bellur < [hidden email]> wrote:
> > > Hi All,
> > >  Is there a way to get the status of a test method (either pass or fail)
> in
> > > TestNG. Let me explain why I require this, with an example.
> > >
> > > I have created a suite file to test two classes
> > >
> > > Class 1: Verifies some value in a page.
> > >      1) User Logs into a Portal
> > >      2) Opens up some page (say Page1) to verify some value
> > >      3) If the Value is not present (the testcase fails)
> > >      4) If the value is present User logs off and goes back to login
> screen.
> > >
> > > Class 2:
> > >       1) User Logs into a portal
> > >       2) Opens up another page (say Page2) to verify some value
> > >       3) If the value is not present (testcase fails)
> > >       4) If the value is present User Logs off and goes back to login
> screen
> > >
> > > Now let us assume Method in Class 1 failed (the value is not present)
> the
> > > user is in Page1.
> > >
> > > So when the method in Class 2 has to run it expects the application to
> be in
> > > Login screen. So my login in Class 2 fails.
> > >
> > > One solution I can think of handling this situation, is to get the state
> of
> > > the testcase of Class 1. (either pass or fail) in some method written in
> > > Class 1 and click on "Log Off" link.  Just like Exception handling.
> > >
> > > This would bring the application to the state which Class 2 expects.
> > >
> > > Please tell me whether my approach would be right or is there an easy
> way to
> > > handle this scenario in TestNG.
> > >
> >
> > Manjunath, after reading your test description the first thing that
> > occured to me is: a couple of steps look to be configuration-like
> > steps. I would perform these steps in configuration methods:
> >
> > Login/Logout: @BeforeX/@AfterX(alwaysRun=true)
> >
> > (you must decide at what level you want this to be run and around what
> > code - if it is expensive then you should raise it to test or group or
> > even suite level).
> >
> > Then you do some more preparing: move to page N (hey, I would do this
> > with a @BeforeClass/@BeforeMethod)... and last the test.
> >
> > So, finally my tests would look like:
> >
> > @BeforeTest or @BeforeGroup
> > - login (if it fails nothing that follows will be run, but reported as
> skipped)
> >
> > ----
> > Class A:
> >
> > @BeforeClass or @BeforeMethod
> > - go to page A
> >
> > @Test
> > - do my test
> >
> > Class B:
> >
> > @BeforeClass or @BeforeMethod
> >
> > @Test
> > - do my test
> >
> > ----
> > @AfterTest or @AfterGroup with alwaysRun=true -- this will assure that
> > other groups or tests will start from a well known status (logout).
> >
> > - logout.
> >
> > Hope this helps,
> >
> > ./alex
> > --
> > .w( the_mindstorm )p.
> >   TestNG co-founder
> > EclipseTestNG Creator
> >
> >
> >
> >
> > > Please let me know if you need any more information on the problem
> mentioned
> > > above. Helping this would be much appreciated.
> > >
> > > Thanks and Regards,
> > > Manjunath
> > >  >
> > >
> >
> >
> >
> >
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---