为了账号安全,请及时绑定邮箱和手机立即绑定

通过可执行 JAR 从 cmdline 执行 Cucumber 测试,无需 Maven

通过可执行 JAR 从 cmdline 执行 Cucumber 测试,无需 Maven

弑天下 2023-10-13 16:44:55
以下是执行的步骤:第 1 步: 基于此,我构建了一个独立的 jar,其中包含使用maven-shade-plugin.pom.xml<build>    <plugins>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-surefire-plugin</artifactId>            <version>2.22.2</version>            <configuration>                <testFailureIgnore>true</testFailureIgnore>                <testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>                <testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>                <reportsDirectory>${project.build.directory}/test-output/${timestamp}</reportsDirectory>            </configuration>        </plugin>        <!-- https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html -->        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-shade-plugin</artifactId>            <version>3.2.1</version>            <executions>                <execution>                    <phase>package</phase>                    <goals>                        <goal>shade</goal>                    </goals>                    <configuration>                        <!-- https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html -->                        <shadedArtifactAttached>true</shadedArtifactAttached>                        <shadedClassifierName>standalone</shadedClassifierName>                        <transformers>                            <!-- https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html -->                                <mainClass>runners.RunCukesTest</mainClass>                            </transformer>                        </transformers>                    </configuration>                </execution>            </executions>        </plugin>    </plugins></build>将该main()方法添加到 runner 类中,并根据this、this和this传递 cmdline 参数。
查看完整描述

1 回答

?
蛊毒传说

TA贡献1895条经验 获得超3个赞

您传递了 Cucumber 的相对路径src\main\resources\features。因为您正在执行 Jar,所以该相对路径将使用当前工作目录转换为绝对路径。但是,因为src\main\resources\features是您的功能的源文件夹,所以找不到任何内容,您会得到:

线程“main”中的异常 java.lang.IllegalArgumentException:不是文件或目录:\path\to\jar\src\main\resources\features

相反,您必须告诉 Cucumber 您的功能位于类路径上。您可以通过以下方式执行此操作:

"classpath:features"


查看完整回答
反对 回复 2023-10-13
  • 1 回答
  • 0 关注
  • 50 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信