Help me understanding "skips" while running test methods

100 views
Skip to first unread message

Jerald paul

unread,
Nov 21, 2011, 5:21:26 AM11/21/11
to testng...@googlegroups.com
Hi,

I ran the following simple test class(Which has only 2 test methods) and found that 0 passed and 1 failed and 5 skipped.  I really don't know what is happening. Some one please help.


package test;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class TestNgTest
{
    @BeforeMethod
    public void setUp() throws Exception
    {
                if(true)
                {
                    throw new Exception("setup method");
                }
    }
   
    @AfterMethod
    public void tearDown() throws Exception
    {
            if(true)
            {
                throw new Exception("teardown method");
            }
    }

    @Test(description = "Test1")
    public void Test1() throws Exception
    {
            if(true)
            {
                throw new Exception("test1 method");
            }
    }

    @Test(description = "Test2")
    public void Test2() throws Exception
    {
            if(false)
            {
                throw new Exception("test2 method");
            }
    }
}

Regards
jerald


Krishnan Mahadevan

unread,
Nov 21, 2011, 5:40:51 AM11/21/11
to testng...@googlegroups.com
This is what I see :

SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED CONFIGURATION: @BeforeMethod setUp
SKIPPED CONFIGURATION: @AfterMethod tearDown
SKIPPED: Test1
         Test1
SKIPPED: Test2
         Test2

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

Explanation :
You have 2 test methods, which explains the skips
There were 3 skips in the configuration section, because @BeforeMethod and @AfterMethod gets called for every @Test Method
Because 1 configuration method failed, the rest of them were skipped.


Thanks & Regards
Krishnan Mahadevan

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



--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/a0H8JuzwKHAJ.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Jerald paul

unread,
Nov 21, 2011, 8:05:41 AM11/21/11
to testng...@googlegroups.com
I feel stupid and dumb as i cant understand what is going on here.

Please correct me if i am wrong.

I expect @BeforeMethod is called before @Test method and then followed by @AfterMethod .

So if an exception occurred in a @BeforeMethod then both the @Test method and @AfterMethod will be added in skipped tests list and @BeforeMethod will be added in failed configs right?

Thanks and Regards
jerald

Krishnan Mahadevan

unread,
Nov 21, 2011, 9:42:34 AM11/21/11
to testng...@googlegroups.com
Yes, your understanding is correct.

@BeforeSuite/@AfterSuite - Executed once per suite
@BeforeClass/@AfterClass - Executed once per instance of class
@BeforeTest/@AfterTest - Executed once per test (for every occurance of <test> tag in the template file)
@BeforeMethod/@AfterMethod = Executed once per every test method (methods annotated with @Test) [ Not sure if this would get called when executing the other configuration methods as well.. never tried it.. you could try and confirm if that is the case)


Thanks & Regards
Krishnan Mahadevan

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



jerald

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/BM2FpJ_ItEAJ.

Cédric Beust ♔

unread,
Nov 21, 2011, 11:04:13 AM11/21/11
to testng...@googlegroups.com
Because your @BeforeMethod is failing, it causes all your @Test methods to be skipped.

-- 
Cédric




--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/a0H8JuzwKHAJ.
Reply all
Reply to author
Forward
0 new messages