[英]In my testNG integration tests can I use @factory more than once (using Jenkins and Maven for my builds)?
What - Detailed Steps 什么-详细步骤
My test calls a 3rd party API and sends a request for a new transaction (let's say I need to do this for 5 tests which were generated by @Factory). 我的测试调用了第三方API,并发送了一个新交易的请求(假设我需要对@Factory生成的5个测试进行此操作)。 These tests end here with the status of 'Pending'.
这些测试在此处以“待处理”状态结束。
The 3rd party API takes 5 minutes to process the data. 第三方API需要5分钟来处理数据。 I need to make a second call to the API after 5 minutes (for all my pending tests) to get the transaction ID for my request and then pass/fail the test.
我需要在5分钟后(对于所有未完成的测试)再次调用API,以获取我的请求的交易ID,然后通过/失败测试。
I want to spin up another @Factory here to re-generate all the Pending tests. 我想在这里启动另一个@Factory,以重新生成所有待处理的测试。 These pending tests call the API again (with different inputs) to get the transaction ID and pass/fail the test based on this info.
这些挂起的测试再次调用API(使用不同的输入)以获取交易ID,并根据此信息通过/失败测试。
How 怎么样
I am trying to use @Factory
to generate a bunch of tests dynamically and run them. 我正在尝试使用
@Factory
动态生成一堆测试并运行它们。 After these tests are run I want to use @Factory
again to generate a second batch of new tests and run them. 这些测试运行之后,我想再次使用
@Factory
生成第二批新测试并运行它们。 The problem is, I did not have success when trying to call @Factory
for the second time. 问题是,第二次尝试调用
@Factory
时,我没有成功。
I am using Jenkins and Maven in my setup for generating builds and that is when I would want the tests to run. 我在我的设置中使用Jenkins和Maven生成内部版本,那就是我希望运行测试的时间。
Questions 问题
Is step 3 possible? 第3步可行吗?
Is there a better way to do this? 有一个更好的方法吗?
Thanks everyone! 感谢大家!
Reading the extra comment / improves question, it sounds indeed like an Integration Test . 阅读额外的注释/改进的问题,听起来确实像是一个集成测试 。
There are some need Integration Test libraries like JBehave , Serenity , Cucumber , etc which would probably better for setting this up. 有一些集成测试库,例如JBehave , Serenity , Cucumber等,可能会更好地进行设置。
With TestNG, you could create 3 tests, where each next test depends on the previous test. 使用TestNG,您可以创建3个测试,每个下一个测试都取决于上一个测试。 See code sample below, from testng dependency test
请参阅下面的代码示例,来自testng依赖测试
package com.mkyong.testng.examples.dependency;
import org.testng.annotations.Test;
public class App {
@Test
public void method1() {
System.out.println("This is method 1");
}
@Test(dependsOnMethods = { "method1" })
public void method2() {
System.out.println("This is method 2");
}
}
Here the most simple dependency is show. 这里最简单的依赖关系是show。 See the sample code for more complex cases, like groups etc. For setting up two test classes each with their own
@Factory
有关更复杂的情况(例如组等),请参见示例代码。有关设置两个测试类的每个实例都具有自己的
@Factory
Solved! 解决了! Responses to this question led me in finding the answer - Thanks @Verhagen
对这个问题的回答使我找到了答案-谢谢@Verhagen
When a build is triggered, 触发构建后,
@Factory 1 creates tests --> @Factory 2 creates more tests --> tests by @Factory 1 are executed --> tests by @Factory 2 are executed
This solves my requirement for running a batch of tests (first batch) and then running a second batch of tests based on the out come of the first batch. 这解决了我运行一批测试(第一批)然后基于第一批测试的结果运行第二批测试的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.