Вот выполненные шаги:
Шаг 1: На основе этого я построил автономную банку со всеми зависимостями, включенными с использованием 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 -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>runners.RunCukesTest</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Добавлен метод main()
в класс бегуна и переданы аргументы cmdline на основе this , this и это .
RunCukesTest.java
package runners;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.cli.Main;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(features = { "src/main/resources/features" }, glue = { "steps" }, tags = { "not @ignore" }, plugin = {
"pretty" }, monochrome = true)
public class RunCukesTest extends AbstractTestNGCucumberTests {
public static void main(String[] args) {
System.out.println("Begin running tests...");
Main.main(new String[]{ "-g", "steps", "-t", "not @ignore", "-p", "pretty", "-m", "src/main/resources/features" });
}
}
Шаг 2: Попытка запустить исполняемый файлJAR.
λ java -jar project-xyz-1.0.0-standalone.jar
Begin running tests...
Exception in thread "main" java.lang.IllegalArgumentException: Not a file or directory: \path\to\jar\src\main\resources\features
at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:63)
at cucumber.runtime.io.FileResourceIterator.<init>(FileResourceIterator.java:28)
at cucumber.runtime.io.FileResourceIterator.createFileResourceIterator(FileResourceIterator.java:14)
at cucumber.runtime.io.FileResourceIterable.iterator(FileResourceIterable.java:19)
at cucumber.runtime.model.FeatureLoader.loadFromFeaturePath(FeatureLoader.java:112)
at cucumber.runtime.model.FeatureLoader.load(FeatureLoader.java:48)
at cucumber.runtime.model.FeatureLoader.load(FeatureLoader.java:30)
at cucumber.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:22)
at cucumber.runtime.Runtime.run(Runtime.java:68)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:8)
at runners.RunCukesTest.main(RunCukesTest.java:17)
Он читает метод main()
в классе бегуна, но выдает
Исключение в потоке "main" java.lang.IllegalArgumentException: Не файл или каталог: \ path \ to \ jar \ src \ main \ resources \ features
ОБНОВЛЕНИЕ
Кажется, он не читает каталог features
внутри JAR.
Main.main(new String[]{ "-g", "steps", "-t", "not @ignore", "-p", "pretty", "-m", "src/main/resources/features" });
Как мне указать каталог features
внутри JAR с помощью аргументов cmdline?