@afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

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

@afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

mlandman99
Hi,

I have tests organized into groups, and when there are no exceptions, everything works as desired. But when there is an exception in @beforeGroups, I'm seeing behavior that seems odd..

@Test exists in class C1, defined as part of group G1

The following sequence of events occurs:

Code from @beforeSuite runs first.
Code from @beforeClass (from C1) runs next
Code from @beforeGroups (from group G1) runs next
An exception occurs in the @beforeGroups code mentioned above.

Next, I would have expected testNG to run the @afterClass code from class C1, since it had run the @beforeClass code..

Instead, it skips all the tests in group G1 (fine, considering the @beforeGroups failed), and then it runs the @beforeClass of class C2 that has the first @Test in group G2, etc.

My question is.. why didn't it run the @afterClass code in C1? I would have thought that since it ran the @beforeClass, it would run the @afterClass.

In general, if there is an exception in the @Test within aclass, it still runs the @afterClass code. So why should it choose to not run the @afterClass code just because the exception was in the @beforeGroups, instead of a @Test? I would have thought if there is a problem in @beforeGroups, that it should run either both @beforeClass and @afterClass....... or neither @beforeClass nor @afterClass. But not just one of the two.

In my scenario, the @beforeClass has some environment preparation, and the @afterClass does some cleanup that I need -- cleaning up some of the things previously set up in the @beforeClass. In this case, the preparation is occurring, but the cleanup isn't occurring.


--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: @afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

mlandman99
Still stumped on this one. :( Any suggestions as to why the @afterClass didn't run in this scenario, whereas the @beforeClass did?


On Monday, August 5, 2013 11:36:57 AM UTC-4, Michael Landman wrote:
Hi,

I have tests organized into groups, and when there are no exceptions, everything works as desired. But when there is an exception in @beforeGroups, I'm seeing behavior that seems odd..

@Test exists in class C1, defined as part of group G1

The following sequence of events occurs:

Code from @beforeSuite runs first.
Code from @beforeClass (from C1) runs next
Code from @beforeGroups (from group G1) runs next
An exception occurs in the @beforeGroups code mentioned above.

Next, I would have expected testNG to run the @afterClass code from class C1, since it had run the @beforeClass code..

Instead, it skips all the tests in group G1 (fine, considering the @beforeGroups failed), and then it runs the @beforeClass of class C2 that has the first @Test in group G2, etc.

My question is.. why didn't it run the @afterClass code in C1? I would have thought that since it ran the @beforeClass, it would run the @afterClass.

In general, if there is an exception in the @Test within aclass, it still runs the @afterClass code. So why should it choose to not run the @afterClass code just because the exception was in the @beforeGroups, instead of a @Test? I would have thought if there is a problem in @beforeGroups, that it should run either both @beforeClass and @afterClass....... or neither @beforeClass nor @afterClass. But not just one of the two.

In my scenario, the @beforeClass has some environment preparation, and the @afterClass does some cleanup that I need -- cleaning up some of the things previously set up in the @beforeClass. In this case, the preparation is occurring, but the cleanup isn't occurring.


--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: @afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

Krishnan Mahadevan
Michael,

Would you be able to share a small reproducible sample that shows this problem ? Also can you please tell us what version of TestNG are you on ?

On Tuesday, August 13, 2013, Michael Landman wrote:
Still stumped on this one. :( Any suggestions as to why the @afterClass didn't run in this scenario, whereas the @beforeClass did?


On Monday, August 5, 2013 11:36:57 AM UTC-4, Michael Landman wrote:
Hi,

I have tests organized into groups, and when there are no exceptions, everything works as desired. But when there is an exception in @beforeGroups, I'm seeing behavior that seems odd..

@Test exists in class C1, defined as part of group G1

The following sequence of events occurs:

Code from @beforeSuite runs first.
Code from @beforeClass (from C1) runs next
Code from @beforeGroups (from group G1) runs next
An exception occurs in the @beforeGroups code mentioned above.

Next, I would have expected testNG to run the @afterClass code from class C1, since it had run the @beforeClass code..

Instead, it skips all the tests in group G1 (fine, considering the @beforeGroups failed), and then it runs the @beforeClass of class C2 that has the first @Test in group G2, etc.

My question is.. why didn't it run the @afterClass code in C1? I would have thought that since it ran the @beforeClass, it would run the @afterClass.

In general, if there is an exception in the @Test within aclass, it still runs the @afterClass code. So why should it choose to not run the @afterClass code just because the exception was in the @beforeGroups, instead of a @Test? I would have thought if there is a problem in @beforeGroups, that it should run either both @beforeClass and @afterClass....... or neither @beforeClass nor @afterClass. But not just one of the two.

In my scenario, the @beforeClass has some environment preparation, and the @afterClass does some cleanup that I need -- cleaning up some of the things previously set up in the @beforeClass. In this case, the preparation is occurring, but the cleanup isn't occurring.


--
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 <a href="javascript:_e({}, &#39;cvml&#39;, &#39;testng-users%2Bunsubscribe@googlegroups.com&#39;);" target="_blank">testng-users+unsubscribe@....
To post to this group, send email to <a href="javascript:_e({}, &#39;cvml&#39;, &#39;testng-users@googlegroups.com&#39;);" target="_blank">testng-users@....
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
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/

--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: @afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

Chuck H
In reply to this post by mlandman99
I am new to testng, and am experiencing the same problem.

We are using version 6.8.7.

A failure in the before group method causes the test to be skipped (as expected), however it also causes the after group  method to be skipped as well. I am trying to use the beforegroup method to perform a setup operation and the aftergroup method to perform a cleanup. I want the cleanup to execute even if the setup failed.

Here is a sample class that demonstrates the behavior.


package BeforeAfterGroup;

import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

import com.equallogic.test.HITAutomation.utilities.TestUtilities;

public class beforeAferGroupTest {
        @BeforeGroups( groups = { "A" })
        public static void setUpBeforeGroupSMP() throws Exception {
                System.out.println("In @BeforeGroups for SMP");
                int a = 5/0;
        }
               
        @AfterGroups( groups = { "A" } , alwaysRun = true)
        public static void cleanUpAfterGroupSMP() throws Exception {
                System.out.println("In @AfterGroups for SMP");
                }
       
        @Test(groups = "A")
        public static void Test () throws Exception {
        System.out.println("This is the test.");
        //int a = 5/0;
        }
}




 If I induce an error in the test method, everything works as expected. If I induce an error in the before class (as is the current state of the example) the after test is skipped.


SKIPPED CONFIGURATION: @AfterGroups cleanUpAfterGroupSMP
SKIPPED: Test

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


Thanks,
Chuck

 
Reply | Threaded
Open this post in threaded view
|

Re: @afterClass not firing when @beforeGroups has an exception (but @beforeClass successful)

Krishnan Mahadevan
Chuck,

I dont think TestNG is built to invoke tearDown methods [ @AfterXX methods] if there is a failure in the setup methods [@BeforeXX methods]. Atleast that is what my understanding is, after I looked at the TestNG codebase.

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/


On Tue, Jan 7, 2014 at 10:11 PM, Chuck H <[hidden email]> wrote:
I am new to testng, and am experiencing the same problem.

We are using version 6.8.7.

A failure in the before group method causes the test to be skipped (as
expected), however it also causes the after group  method to be skipped as
well. I am trying to use the beforegroup method to perform a setup operation
and the aftergroup method to perform a cleanup. I want the cleanup to
execute even if the setup failed.

Here is a sample class that demonstrates the behavior.


package BeforeAfterGroup;

import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

import com.equallogic.test.HITAutomation.utilities.TestUtilities;

public class beforeAferGroupTest {
        @BeforeGroups( groups = { "A" })
        public static void setUpBeforeGroupSMP() throws Exception {
                System.out.println("In @BeforeGroups for SMP");
                int a = 5/0;
        }

        @AfterGroups( groups = { "A" } , alwaysRun = true)
        public static void cleanUpAfterGroupSMP() throws Exception {
                System.out.println("In @AfterGroups for SMP");
                }

        @Test(groups = "A")
        public static void Test () throws Exception {
        System.out.println("This is the test.");
        //int a = 5/0;
        }
}




 If I induce an error in the test method, everything works as expected. If I
induce an error in the before class (as is the current state of the example)
the after test is skipped.


SKIPPED CONFIGURATION: @AfterGroups cleanUpAfterGroupSMP
SKIPPED: Test

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================


Thanks,
Chuck





--
View this message in context: http://testng.1065351.n5.nabble.com/afterClass-not-firing-when-beforeGroups-has-an-exception-but-beforeClass-successful-tp18627p19269.html
Sent from the testng-users mailing list archive at Nabble.com.

--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.

--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/groups/opt_out.