当前位置: 首页 > 知识库问答 >
问题:

无法使用 Maven 构建运行配置运行cucumber测试

沈博延
2023-03-14

我正在尝试使用 maven build 作为运行配置在 eclipse 中运行cucumber测试。当我运行配置时,构建成功,但浏览器不调用。因此,测试未运行。测试被跳过,给出一个信息“没有什么可编译的 - 所有类都是最新的”。我能够通过将功能文件作为cucumber功能运行来成功运行相同的测试。

请告诉我为什么要跳过测试。也让我知道运行maven构建cucumber测试的步骤。下面是我使用的pom.xml。我还使用vm参数作为“-Dcucumber. Options=--格式html:目标/cucumber-html-Report--tages@Runme”

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>


  <groupId>Maven.Project</groupId>
  <artifactId>testMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Maven.Project-v1-testMaven</name>


    <properties>
        <corporate.test.url>http://google.com</corporate.test.url>
        <corporate.test.browser>Firefox</corporate.test.browser>
        <corporate.selenium.url>http://localhost:8888/wd/hub</corporate.selenium.url>
    </properties>

  <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.42.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>1.1</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>test</id>
            <properties>
                <corporate.test.url>http://acc-about.hm.com</corporate.test.url>
                <corporate.test.browser>Firefox</corporate.test.browser>
                <corporate.selenium.url>http://localhost:8888/wd/hub</corporate.selenium.url>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.10</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
    </build>


</project>

共有1个答案

贺波
2023-03-14

请删除maven-surefire插件中的skiptests标签。。。

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
       <skipTests>true</skipTests>
</configuration>

编辑:请在配置中添加以下行

<suiteXmlFiles>
    <suiteXmlFile>${basedir}${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>./test-output/archive/${timestamp}</reportsDirectory>

在这里,suiteXmlFile指向您试图运行的xml文件,reportsDirectory指向您的输出文件夹。在命令行中,或者如果在目标中使用eclipse,提供干净的测试-DsuiteFile=

希望这能有所帮助。

 类似资料:
  • 有没有人能告诉我为什么我不能使用Maven运行任何测试。 已配置SureFire插件 在runner类下设置胶合代码 “测试”被追加到runner类 注意:如果我将文件作为Junit运行,那么它可以正确地运行所有场景。只有当我使用Maven运行它时,才不会运行任何测试。

  • 我遇到了无法使用Maven运行JUnit5测试的问题。在IDE中运行它们工作正常,但使用“mvn测试”会产生以下输出: 这是我的测试课程: pom: 我做了一些研究,我认为这可能与混合JUnit4和JUnit5特性有关,这导致maven surefire插件无法运行测试。然而,我找不到那些剩余的JUnit4特性可能在哪里。我将感谢任何帮助。

  • 我试图使用TestNG和SpringBootTest并行运行两个Cucumber测试,但当我的测试执行时,会发生以下情况 两个浏览器都打开并导航到维基百科主页 1个浏览器继续测试,另一个留在主页上 1个测试通过,另一个测试失败 我不知道为什么一个测试会停止执行,欢迎任何帮助。 回购:https://github.com/cmccarthyIrl/spring-cucumber-testng-par

  • 如何使用Maven在以下位置运行cucumber测试。 源文件夹'src/main/java'和'src/main/resources'包括在每个源文件夹中创建的包'com.testing.testproject.login'中的步骤定义和功能文件。 这是我的POM文件: 提前道谢。

  • 我注意到,有时在Jenkins上运行maven构建时,运行的Jbehave测试的数量会因运行的不同而不同。在分析日志时,我看到以下代码段: 问题是,当跳过测试或以这种方式运行失败时,构建仍然被视为成功。 是否有maven surefire插件配置,可以确保在测试失败时运行构建会导致失败?以下是maven surefire构建配置

  • 我们有一组UI测试每晚运行,有时一些测试由于网络故障而失败。为了避免假阴性测试结果,我使用了,它可以重新运行失败的测试多达3次。 当我从Eclispe右键单击套件运行测试时,它工作得非常好。xml—如果测试最初失败,但重试时通过,则第一个结果不算作失败。 但是,当作为Maven构建的一部分运行相同的测试时,如果任何测试失败,即使在重试时成功通过,构建也会失败。 例如,运行一个包含5个测试的套件,其