Testng 如果发现套件运行模式为N(从Excel读取),如何停止套件中所有Testcase的执行
嗨,当我运行我的代码时,我能够从excel中读取运行模式为N,并且系统正在抛出新的异常。但是,在为SuiteB创建了一个SkippeException之后,它仍然会运行并执行SuiteB中的所有测试用例。 如果@beforesuite方法中出现skippException,系统将停止执行该套件的所有Testcase 我的书包里有三节课 TestSuiteBase 测试用例B1 测试用例2Testng 如果发现套件运行模式为N(从Excel读取),如何停止套件中所有Testcase的执行,testng,Testng,嗨,当我运行我的代码时,我能够从excel中读取运行模式为N,并且系统正在抛出新的异常。但是,在为SuiteB创建了一个SkippeException之后,它仍然会运行并执行SuiteB中的所有测试用例。 如果@beforesuite方法中出现skippException,系统将停止执行该套件的所有Testcase 我的书包里有三节课 TestSuiteBase 测试用例B1 测试用例2 package com.qtpselenium.suiteB; import org.te
package com.qtpselenium.suiteB;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import com.qtpselenium.base.TestBase;
import com.qtpselenium.util.TestUtil;
public class TestSuiteBase extends TestBase{
@BeforeSuite
public void checksuiteskip(){
try {
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
Initialize();
App_Logs.debug("checking run mode of SuiteB");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteB")){
App_Logs.debug("Run mode for suiteB is N");
throw new SkipException("Run mode for suiiteB is N");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
******************TestcaseB1****
package com.qtpselenium.suiteB;
import org.testng.annotations.Test;
public class TestCaseB1 extends TestSuiteBase{
@Test(dependsOnMethods="com.qtpselenium.suiteB.TestSuiteBase.checksuiteskip")
public void TestcaseB1(){
System.out.println("We are in Test case B1");
}
}
************************TestcaseB2**********
package com.qtpselenium.suiteB;
import org.testng.annotations.Test;
public class TestCaseB2 extends TestSuiteBase{
@Test(dependsOnMethods="com.qtpselenium.suiteB.TestSuiteBase.checksuiteskip")
public void TestcaseB2(){
System.out.println("We are in Test case B2");
}
}
这是因为,在抛出
SkipException
之后,您也捕获了异常。
将您的beforeSuite
更改为如下内容。这会解决你的问题
@BeforeSuite
public void checksuiteskip(){
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
Initialize();
App_Logs.debug("checking run mode of SuiteB");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteB")){
App_Logs.debug("Run mode for suiteB is N");
throw new SkipException("Run mode for suiiteB is N");
}
}
这是因为,在抛出
SkipException
之后,您也捕获了异常。
将您的beforeSuite
更改为如下内容。这会解决你的问题
@BeforeSuite
public void checksuiteskip(){
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
Initialize();
App_Logs.debug("checking run mode of SuiteB");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteB")){
App_Logs.debug("Run mode for suiteB is N");
throw new SkipException("Run mode for suiiteB is N");
}
}
代码被更改,最后代码如下所示。如果套件的运行模式为N,则跳过整个套件可以正常工作
package com.qtpselenium.suiteC;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import com.qtpselenium.base.TestBase;
import com.qtpselenium.util.TestUtil;
public class TestSuiteBase extends TestBase{
@BeforeSuite
public void checksuiteskip(){
try {
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
Initialize();
} catch (Exception e) {
e.printStackTrace();
}
App_Logs.debug("checking run mode of SuiteC");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteC")){
App_Logs.debug("Run mode for suiteC is N");
throw new SkipException("Run mode for suiiteC is N");
}else
App_Logs.debug("Run mode for SuiteC is Y");
}
}
代码被更改,最后代码如下所示。如果套件的运行模式为N,则跳过整个套件可以正常工作
package com.qtpselenium.suiteC;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import com.qtpselenium.base.TestBase;
import com.qtpselenium.util.TestUtil;
public class TestSuiteBase extends TestBase{
@BeforeSuite
public void checksuiteskip(){
try {
//Initialize method of Test BASE Class to Initialize the logs and all the excel files
Initialize();
} catch (Exception e) {
e.printStackTrace();
}
App_Logs.debug("checking run mode of SuiteC");
if( !TestUtil.isSuiterunnable(suitexlsx, "suiteC")){
App_Logs.debug("Run mode for suiteC is N");
throw new SkipException("Run mode for suiiteC is N");
}else
App_Logs.debug("Run mode for SuiteC is Y");
}
}