Conditional skipping of TestNG tests

后端 未结 5 1202
猫巷女王i
猫巷女王i 2021-02-09 07:21

I don\'t have much experience with TestNG annotations, however I am trying to build a test suite using TestNG framework and POM design pattern for a retail website. I am plannin

5条回答
  •  無奈伤痛
    2021-02-09 08:06

    throw new skipException("skipping the test case")
    

    It will just skip the test case not the complete suite. Instead of checking the suite Run mode, check the Run mode of test case as Y/N in the @beforeTest Method. Then if you found the run mode as N, throw an exception .

    throw new skipException("skipping test case as run mode is y").
    

    This will skip your test case. This is just an alternative even I didn't find any other way to skip the complete suite. The above case will fill the purpose just need to keep the run mode of each test case as N, if you don't want to run that suite. It will skip all the test cases of that suite and will be part of your report that these test cases were skipped.

    Example is as given below

    package com.qtpselenium.suiteC;
    
    import org.testng.SkipException;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    import com.qtpselenium.util.TestUtil;
    
    public class TestCaseC1 extends TestSuiteBase{
    
    
        //Checking runMode of the Test case in Suite
            @BeforeTest
            public void checkTestcaseskip(){
    
                //this.getclass().getSimpleName() method returns the name of the class
                App_Logs.debug("checking run mode of " +this.getClass().getSimpleName() + " testcase");
                if(!TestUtil.IsTestCaseRunnable(suiteCxlsx, this.getClass().getSimpleName())){
                    App_Logs.debug("Run mode of testcase " + this.getClass().getSimpleName() + " is N");
                    throw new SkipException("Run mode of testcase " + this.getClass().getSimpleName() + " is N");
    
                }else
    
                App_Logs.debug("Run mode of testcase " + this.getClass().getSimpleName() + " is Y");
            }
    
            @Test(dataProvider="getTestData")
            public void TestcaseC1(
    
                                  String col1,
                                  String col2,
                                  String col3,
                                  String col4
    
                                 ){
    
    
                App_Logs.debug("Test data of testcase : " +  this.getClass().getSimpleName());
                App_Logs.debug(col1+"--"+col2+"--"+col3+"--"+col4);
    
    
        }
    
        //Data provide to TestcaseC1
                @DataProvider
                public Object[][] getTestData(){
    
    
                    return TestUtil.getdata(suiteCxlsx, this.getClass().getSimpleName());
    
    
                }
    
    }
    

提交回复
热议问题