青瓜(Cucumber)和JUnit在Jenkins(Surefire)中测试数量错误

4
当我尝试通过Maven(surefire)同时使用Cucumber和Junit时,报告显示的测试数量不正确。我只有250个测试,但Jenkins却显示了1200个测试。因此,当我进行调查时,我只能找到一个参考,即surefire插件存在问题。

https://github.com/cucumber/cucumber-jvm/issues/322

如何更正它?
3个回答

1

我只能使用surefire创建hack。如果你喜欢,可以使用以下方法:

  1. 创建Cucumber的junit报告并将其保存到某个文件夹(1)“cucumber”中。
  2. 将surefire报告(不包括由surefire生成的Cucmber报告)复制到某个文件夹(2)“surefire-reports-fixed”中,其中cucumber生成了报告。
  3. 从(1)复制Cucumber junit报告到(2)
  4. Jenkins必须使用文件夹(2)“surefire-reports-fixed”

Maven中的示例更改:

 <plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>change-bad-cucumber-test-file</id>
                        <!-- here the phase you need -->
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/surefire-reports-fixed</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/target/cucumber</directory>
                                </resource>
                                <resource>
                                    <directory>${basedir}/target/surefire-reports</directory>
                                    <excludes>
                                        <exclude>**/*CucumberTest.*</exclude>
                                    </excludes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

CucumberTest.java的更改:

@RunWith(Cucumber.class)
@Cucumber.Options(format = { "pretty", "junit:target/cucumber/TEST-packageHereToClass.CucumberTest.xml", "json:target/cucumber.json" })
public class CucumberTest {
 ...
}

在 Jenkins 中设置测试的 surefire 文件夹为 (2) 'surefire-reports-fixed'


0
以下方法适用于我 - 我在@cucumbeOptions中添加了cucumber-junit报告格式,即 - "junit:target / surefire-reports / TEST-TestSuite.xml",然后当我在eclipse(也在VSO中)运行时,Junit报告将生成在TEST-TestSuite.xml文件中,并显示正确的计数。
下面是代码 - >
    @CucumberOptions(
                features= {"src/test/resources/Features"},
                plugin   = {"pretty:STDOUT","html:Reports/cucumber-pretty","junit:target/surefire-reports/TEST-TestSuite.xml",               "com.cucumber.listener.ExtentCucumberFormatter:Reports/Reporting/Quixxi_Report.html"},
                monochrome = true,
                dryRun=false
           )

0

我可以理解没人关心它。对我来说,在使用Maven-Surefire插件的2.12版本时,不需要进行上述任何工作流程的更改便可以正常使用。但是在新的Surefire插件版本中(2.18.1),它却无法正常工作。 - kadkaz
maven-surefire-plugin 2.12版本仅支持JUnit并行测试,而2.18.1版本则可以无问题地支持TestNG。 - kadkaz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接