@BeforeTest or @BeforeClass failed, but still @Test runs thru @Factory

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

@BeforeTest or @BeforeClass failed, but still @Test runs thru @Factory

gram
Hi All,

I am facing issue when "@BeforeTest" fails, the "@Test" runs thru "@Factory". Ideally, when "@BeforeTest" fails, the test should be skipped but here it's not doing so, @Test is getting executed.

Please shed light on this issue or let me know what I am missing some important stuff.

TestNG XML:
------------------
<test name="FactoryTest">
    <parameter name="callSSO" value="com.acc.Test1.callSSO"/>
    <groups>
        <run>
            <include name="@mode@"/>
        </run>
     </groups>
     <classes>
       <class name="com.acc.FactoryTest"/>
     </classes>
</test>


Test Class:
-----------------
public class ADFSTest {

    public ADFSTest(Object testData) {
        this.testData = (ArrayList) testData;
    }

    @Factory
    public Object[] createTestInstances() {
        Object[] testInstances = null;
        try {
            finalList = getTestData();                         <<<<---- GETS TEST INPUT FROM FILE (no complex stuff)
            testInstances = new Object[finalList.size()];
            for (int i = 0; i < finalList.size(); i++)
                testInstances[i] = new ADFSTest(finalList.get(i));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return testInstances;
    }

   
    @BeforeTest(groups = { "group1" })
    public void setUp() throws Exception {
        boolean isADFSConfigComplete = false;
        try {
                System.out.println("*** IN SETUP ***");
                isADFSConfigComplete = adfsConfig.setUp();         <<<<------- THROWS SOME EXCEPTION IF SOME THINGS GOES WRONG
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
  
    @AfterTest(groups = { "group1" })
    public void cleanUp() throws Exception {
        try {
                System.out.println("*** IN CLEANUP ***");
            }
        } catch (Exception e) {
            e.printStackTrace();*
        }
    }
  
    @Parameters({ "com.acc.Test1.callSSO" })
    @Test(groups = { "group1" })
    public void callSSO(String testName1) throws Exception {
        String testName = testData.get(0).toString();
        String initOp = testData.get(1).toString();
        String userState = testData.get(2).toString();
        String authScheme = testData.get(3).toString();
        String user = testData.get(4).toString();
       
        System.out.println("------------>> TestName is " + testName);
        System.out.println("------------>> InitOp is " + initOp);
        System.out.println("------------>> UserState is " + userState);
        System.out.println("------------>> AuthScheme is " + authScheme);
        System.out.println("------------>> User is " + user);
        if(user.equals("Fred")
            assert true;
        else
            assert false;
    }
}

TestNG jar (being used): testng-5.10-jdk15.jar

Thanks
gram

--
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: @BeforeTest or @BeforeClass failed, but still @Test runs thru @Factory

Krishnan Mahadevan
Ganesh,

If the code snippet in question is this :

 @BeforeTest(groups = { "group1" })
    public void setUp() throws Exception {
        boolean isADFSConfigComplete = false;
        try {
                System.out.println("*** IN SETUP ***");
                isADFSConfigComplete = adfsConfig.setUp();         <<<<------- THROWS SOME EXCEPTION IF SOME THINGS GOES WRONG
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }


Then I believe that the bug is in your code, because you wrapped up the call to adfsConfig.setUp() within a try..catch block, and you are gobbling all Exceptions and DOING nothing with it.

Either get rid of the try catch block (or) catch the Exception, do some logging or whatever you need and throw back the exception




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, Aug 13, 2013 at 10:02 AM, gram <[hidden email]> wrote:
Hi All,

I am facing issue when "@BeforeTest" fails, the "@Test" runs thru "@Factory". Ideally, when "@BeforeTest" fails, the test should be skipped but here it's not doing so, @Test is getting executed.

Please shed light on this issue or let me know what I am missing some important stuff.

TestNG XML:
------------------
<test name="FactoryTest">
    <parameter name="callSSO" value="com.acc.Test1.callSSO"/>
    <groups>
        <run>
            <include name="@mode@"/>
        </run>
     </groups>
     <classes>
       <class name="com.acc.FactoryTest"/>
     </classes>
</test>


Test Class:
-----------------
public class ADFSTest {

    public ADFSTest(Object testData) {
        this.testData = (ArrayList) testData;
    }

    @Factory
    public Object[] createTestInstances() {
        Object[] testInstances = null;
        try {
            finalList = getTestData();                         <<<<---- GETS TEST INPUT FROM FILE (no complex stuff)
            testInstances = new Object[finalList.size()];
            for (int i = 0; i < finalList.size(); i++)
                testInstances[i] = new ADFSTest(finalList.get(i));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return testInstances;
    }

   
    @BeforeTest(groups = { "group1" })
    public void setUp() throws Exception {
        boolean isADFSConfigComplete = false;
        try {
                System.out.println("*** IN SETUP ***");
                isADFSConfigComplete = adfsConfig.setUp();         <<<<------- THROWS SOME EXCEPTION IF SOME THINGS GOES WRONG
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
  
    @AfterTest(groups = { "group1" })
    public void cleanUp() throws Exception {
        try {
                System.out.println("*** IN CLEANUP ***");
            }
        } catch (Exception e) {
            e.printStackTrace();*
        }
    }
  
    @Parameters({ "com.acc.Test1.callSSO" })
    @Test(groups = { "group1" })
    public void callSSO(String testName1) throws Exception {
        String testName = testData.get(0).toString();
        String initOp = testData.get(1).toString();
        String userState = testData.get(2).toString();
        String authScheme = testData.get(3).toString();
        String user = testData.get(4).toString();
       
        System.out.println("------------>> TestName is " + testName);
        System.out.println("------------>> InitOp is " + initOp);
        System.out.println("------------>> UserState is " + userState);
        System.out.println("------------>> AuthScheme is " + authScheme);
        System.out.println("------------>> User is " + user);
        if(user.equals("Fred")
            assert true;
        else
            assert false;
    }
}

TestNG jar (being used): testng-5.10-jdk15.jar

Thanks
gram

--
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.
 
 
Reply | Threaded
Open this post in threaded view
|

Re: @BeforeTest or @BeforeClass failed, but still @Test runs thru @Factory

gram
Thanks Krishnan, it worked. Kudos.


On Monday, August 12, 2013 10:26:06 PM UTC-7, Krishnan wrote:
Ganesh,

If the code snippet in question is this :

 @BeforeTest(groups = { "group1" })
    public void setUp() throws Exception {
        boolean isADFSConfigComplete = false;
        try {
                System.out.println("*** IN SETUP ***");
                isADFSConfigComplete = adfsConfig.setUp();         <<<<------- THROWS SOME EXCEPTION IF SOME THINGS GOES WRONG
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }


Then I believe that the bug is in your code, because you wrapped up the call to adfsConfig.setUp() within a try..catch block, and you are gobbling all Exceptions and DOING nothing with it.

Either get rid of the try catch block (or) catch the Exception, do some logging or whatever you need and throw back the exception




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, Aug 13, 2013 at 10:02 AM, gram <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mTK-49UtF0sJ">ganesh...@...> wrote:
Hi All,

I am facing issue when "@BeforeTest" fails, the "@Test" runs thru "@Factory". Ideally, when "@BeforeTest" fails, the test should be skipped but here it's not doing so, @Test is getting executed.

Please shed light on this issue or let me know what I am missing some important stuff.

TestNG XML:
------------------
<test name="FactoryTest">
    <parameter name="callSSO" value="com.acc.Test1.callSSO"/>
    <groups>
        <run>
            <include name="@mode@"/>
        </run>
     </groups>
     <classes>
       <class name="com.acc.FactoryTest"/>
     </classes>
</test>


Test Class:
-----------------
public class ADFSTest {

    public ADFSTest(Object testData) {
        this.testData = (ArrayList) testData;
    }

    @Factory
    public Object[] createTestInstances() {
        Object[] testInstances = null;
        try {
            finalList = getTestData();                         <<<<---- GETS TEST INPUT FROM FILE (no complex stuff)
            testInstances = new Object[finalList.size()];
            for (int i = 0; i < finalList.size(); i++)
                testInstances[i] = new ADFSTest(finalList.get(i));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return testInstances;
    }

   
    @BeforeTest(groups = { "group1" })
    public void setUp() throws Exception {
        boolean isADFSConfigComplete = false;
        try {
                System.out.println("*** IN SETUP ***");
                isADFSConfigComplete = adfsConfig.setUp();         <<<<------- THROWS SOME EXCEPTION IF SOME THINGS GOES WRONG
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
  
    @AfterTest(groups = { "group1" })
    public void cleanUp() throws Exception {
        try {
                System.out.println("*** IN CLEANUP ***");
            }
        } catch (Exception e) {
            e.printStackTrace();*
        }
    }
  
    @Parameters({ "com.acc.Test1.callSSO" })
    @Test(groups = { "group1" })
    public void callSSO(String testName1) throws Exception {
        String testName = testData.get(0).toString();
        String initOp = testData.get(1).toString();
        String userState = testData.get(2).toString();
        String authScheme = testData.get(3).toString();
        String user = testData.get(4).toString();
       
        System.out.println("------------>> TestName is " + testName);
        System.out.println("------------>> InitOp is " + initOp);
        System.out.println("------------>> UserState is " + userState);
        System.out.println("------------>> AuthScheme is " + authScheme);
        System.out.println("------------>> User is " + user);
        if(user.equals("Fred")
            assert true;
        else
            assert false;
    }
}

TestNG jar (being used): testng-5.10-jdk15.jar

Thanks
gram

--
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:" target="_blank" gdf-obfuscated-mailto="mTK-49UtF0sJ">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mTK-49UtF0sJ">testng...@....
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.