此时标题可能有点令人困惑;希望我能清理它。
我有什么
我正在使用Selenium WebDriver运行Cucumber JVM来自动化我们的系统测试用例。这些测试用例目前使用XRay Test Management插件存储在JIRA中。 XRay还提供API来获取功能文件,并将结果上传回JIRA。
我创建了一个自定义JIRA实用程序类,将测试作为功能文件下载,并将测试结果从JIRA上传到JIRA,并证明它确实有效。它们分别在Cucumber Runner类的@BeforeClass和@AfterClass中运行。
我还证明了开发的测试框架可以通过手动运行在我的计算机上创建的功能文件来运行。
我想要什么
我希望能够(最终)使用我们的CI工具自动运行自动化测试框架。除此之外,它将从JIRA中提取定义的自动化测试并将测试结果推回JIRA。
我不希望功能文件与代码一起存储。在我看来,这会破坏它的动态目的,因为我们执行的测试会随着时间的推移而改变(执行的数量和步骤本身)。
发生了什么(或者更具体地说,没有发生)
当我尝试在框架中没有任何特征文件的情况下执行Cucumber Runner类时,Cucumber说"在[src / test / resources / features /]"中找不到任何功能。这是可以理解的,因为还没有功能文件。
但是,它不会运行@BeforeClass;因此它不下载要运行的功能文件。我在跑步者课程中尝试了这个有和没有标签。
代码
@RunWith(Cucumber.class)
@CucumberOptions(
tags={"@smoketests"},
features= {"src/test/resources/features/"},
plugin={"json:target/reports/cucumber.json"},
monochrome=true)
public class RunCucumberTest {
@BeforeClass
public static void executeBeforeTests() {
JiraUtil.getFeatureFiles();
//String browser = "firefox";
String browser = "chrome";
//String browser = "safari";
//String browser = "edge";
//String browser = "ie";
DriverUtil.getInstance().setDriver(browser);
}
@AfterClass
public static void executeAfterTests() {
DriverUtil.getInstance().resetDriver();
JiraUtil.uploadTestResults();
}
}
回到我的问题
如何执行JIRA Util代码以便下载功能文件?
有可能实现我想要的吗?或者我是否必须承认失败并且只是将所有功能文件与代码一起存储?
答案 0 :(得分:0)
这是使用JUnit时的预期行为。如果套件中没有测试或者忽略所有测试[1],测试套件将不会调用[==========] Running 21 test(s).
[ RUN ] passing_test
[ OK ] passing_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] line_aware_test
(shared) between tests, line=42 memory=Nine for Mortal Men, doomed to die,
[ OK ] line_aware_test
[ RUN ] line_aware_test
(shared) between tests, line=42 memory=Nine for Mortal Men, doomed to die,
[ OK ] line_aware_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] line_aware_test
(shared) between tests, line=42 memory=One string to rule them all, One Ring to find them,
[ OK ] line_aware_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ OK ] string_recite_test
[ RUN ] string_recite_test
[ ERROR ] --- "Three strings for the Elven-kings under the sky," != "Not quite what I expected"
[ LINE ] --- aa.c:100: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] string_recite_test
[ ERROR ] --- "even for the Dwarf-lords in halls of stone," != "Not quite what I expected"
[ LINE ] --- aa.c:101: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] line_aware_test
(shared) between tests, line=42 memory=Not quite what I expected
[ OK ] line_aware_test
[ RUN ] string_recite_test
[ ERROR ] --- "Nine for Mortal Men, doomed to die," != "Not quite what I expected"
[ LINE ] --- aa.c:102: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] string_recite_test
[ ERROR ] --- "One for the Dark Lord on his dark throne" != "Not quite what I expected"
[ LINE ] --- aa.c:103: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] string_recite_test
[ ERROR ] --- "In the Land of Mordor where the Shadows lie." != "Not quite what I expected"
[ LINE ] --- aa.c:104: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] string_recite_test
[ ERROR ] --- "One string to rule them all, One Ring to find them," != "Not quite what I expected"
[ LINE ] --- aa.c:105: error: Failure!
[ FAILED ] string_recite_test
[ RUN ] failing_test
[ ERROR ] --- "Sorry"
[ LINE ] --- aa.c:79: error: Failure!
[ FAILED ] failing_test
[==========] 21 test(s) run.
[ PASSED ] 14 test(s).
[ FAILED ] 7 test(s), listed below:
[ FAILED ] string_recite_test
[ FAILED ] string_recite_test
[ FAILED ] string_recite_test
[ FAILED ] string_recite_test
[ FAILED ] string_recite_test
[ FAILED ] string_recite_test
[ FAILED ] failing_test
7 FAILED TEST(S)
,@BeforeClass
或@AfterClass
。这样可以避免执行潜在的昂贵设置。
这意味着您无法使用类规则来引导测试。你也不应该这样做。在构建过程中,最好在编译之前获取所有源和资源。
如果您正在使用maven,则可以编写maven,并将其附加到@ClassRule
阶段[2]。创建一个maven插件比JUnit规则更复杂,但并不过分。检查Guide to Developing Java Plugins。
我假设Gradle有类似的选项。