gpt4 book ai didi

java - 我希望根据 Excel 中声明的运行模式运行测试用例

转载 作者:行者123 更新时间:2023-12-01 12:50:13 24 4
gpt4 key购买 nike

请找到以下代码和最后提到的查询。

**注释列表**

public interface AnnotationList{

@Documented

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.TYPE)

public @interface QCID {


String[] value();

}

@Documented

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.TYPE)

public @interface Author {


String value();

}

@Documented

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD)

public @interface Order {


int value();

}


@Documented

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.METHOD)

public @interface MyTest {


static class None extends Throwable {

private static final long serialVersionUID = 1L;


private None() {


}}

JUnitLink

public class JunitLink extends BlockJUnit4ClassRunner {


// TODO work in test status to see if things should be run.


public static final Logger logger = LoggerFactory.getLogger(JunitLink.class);


public JunitLink(Class<?> klass) throws InitializationError {

super(klass);
}


@Override

public void run(final RunNotifier notifier) {

JunitLink.super.run(notifier);
}



@Override

protected List<FrameworkMethod> computeTestMethods() {

List<FrameworkMethod> classMethods = getTestClass().getAnnotatedMethods(AnnotationList.MyTest.class);

SortedMap<Integer, FrameworkMethod> sortedTestMethodList = new TreeMap<Integer,FrameworkMethod>();

for (FrameworkMethod seleniumTest : classMethods) {

if (seleniumTest.getAnnotation(AnnotationList.Order.class) != null) {

sortedTestMethodList.put(seleniumTest.getAnnotation(AnnotationList.Order.class).value(),seleniumTest);

}

}

return new ArrayList<FrameworkMethod>(sortedTestMethodList.values());

}


@Override

protected void runChild(FrameworkMethod method, RunNotifier notifier) {

EachTestNotifier eachNotifier = makeNotifier(method, notifier);

if (method.getAnnotation(Ignore.class) != null) {

runIgnored(eachNotifier);

} else {

runNotIgnored(method, eachNotifier);

}

logger.info("Test {} run completed", method.getName());
}


private int runNotIgnored(FrameworkMethod method,EachTestNotifier eachNotifier) {

int failures = 0;

eachNotifier.fireTestStarted();

try {

methodBlock(method).evaluate();

}
catch (AssumptionViolatedException e) {

eachNotifier.addFailedAssumption(e);

logger.error("Test {} failed!", method.getName());

failures++;
}
catch (Throwable e) {

eachNotifier.addFailure(e);

logger.error("Test {} failed!", method.getName());

failures++;

} finally {

eachNotifier.fireTestFinished();

}

return failures;

}


private void runIgnored(EachTestNotifier eachNotifier) {


eachNotifier.fireTestIgnored();

}


private EachTestNotifier makeNotifier(FrameworkMethod method,RunNotifier notifier) {

Description description = describeChild(method);


return new EachTestNotifier(notifier, description);

}}

启动测试

@RunWith(JunitLink.class)

public class StartUp extends SeleneseTestBase {

public static readProperties settings = new readProperties();

public static final Logger LOGGER = LoggerFactory.getLogger(INF.class);
public static WebDriver driver;


public static Actions actions;




@Override

@Before
public void setUp()
{

}


@Override

@After
public void tearDown() {

}


@BeforeClass

public static void StartBrowser() {

//Start Driver etc

}


@AfterClass

public static void tearClassDown() {

//Kill driver

}
}

//测试用例是这样写的

@Author("XXXX")


@QCID({ "Smoke_TC01", "Smoke_TC02", "Smoke_TC03",
"TC04"})

public class SmokeTest extends Startup{

private Components component = new Components();
private String TestDataSheetName = "Smoke";

public SmokeTest() throws Exception {

}

@MyTest
@Order(1)
public void openHomepage() throws Exception {
component.openAPP();
}

@MyTest
@Order(2)
public void Login() throws Exception {
component.Login(USID, PWD);

}

@MyTest
@Order(3)
public void isTerminalLocked() throws Exception {
component.isTerminalLocked();
}

所有测试方法按顺序运行。现在我只想运行在 Excel 中声明运行模式为"is"的特定测试用例。我可以在每个测试用例之前添加额外行以从 excel 读取行并运行特定的测试用例,但我想读取 excel 并将选定的测试用例(基于运行模式)传递给 Junit 运行程序。

请帮助我。

最佳答案

我认为你的问题“太宽泛”了。它可能会因此而关闭。

看看A JUnit Rule to Conditionally Ignore Tests 。由此,您的 isSatisfied() 将必须解析您的 Excel。您可以使用类似 Apache POI 的内容来做到这一点。

关于java - 我希望根据 Excel 中声明的运行模式运行测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24279362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com