私はキュウリとmavenのプロジェクトも持っています。私はJUnitも使用しています。キュウリのテストを実行可能なjarから直接実行する
Eclipseからプロジェクトを実行して正常にビルドすることができます。
今は、Eclipseまたはキュウリがインストールされていない(別のシステムで)コマンドラインからテストを実行したいとします。 jarからJARを作成できるという考えがあり、java cliコマンドでテストを実行できます。以下は
は私が
のpom.xml
<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>pmc</groupId>
<artifactId>se</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>storeEnabler</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.11-beta3</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resource</directory>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_60\bin\javac.exe</executable>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>cucumber.api.cli.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
...また、私はのpom.xmlとRunCukesTest.javaファイルを貼り付けていますから、私のテストを実行しようとしていますそれらの組み合わせであります
RunCukesTest.java
package se.stepDefinations;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resource/features/Printing.feature:117", plugin = { "pretty",
"html:target/cucumber-html-report" }, glue = { "se.stepDefinations" }, tags = {})
public class RunCukesTest {
public static void main(String[] args) throws Exception {
}
}
- クラスパスにJUNIT Jarを追加しました。
私は2通りの方法でjarファイルを生成しています、
1)を使用して、JARのエクスポート - >プロジェクト - >エクスポート - > JARファイル として最後のステップでメインクラスを選択する:私はmainメソッドを定義しているようRunCukesTestここでのエントリポイントのため(私たちは、このクラスでは、このmainメソッドが必要なん???)
輸出した後、私は、コマンドの下に
1.1 java -jar xyz.jar
を実行しています、私はエラーを取得:NoClassDefが見つかりました:ORG/JUnitのを/ランナー/ JUnitCore は、だから私はそれをこのように走っ:
1.2 java -cp xyz.jar;junit-4.12.jar org.junit.runner.JUnitCore
それは言った、それはまだdidntの仕事
JUnit version 4.12
Time:0.001
OK(0 tests)
を、だから私は、最後にRunCukesTestファイルの名前空間を追加
1.3 java -cp xyz.jar;junit-4.12.jar org.junit.runner.JUnitCore se.stepDefinations.RunCukesTest
それは私にエラーを与えた:タイプcucumber.api.junit.Cucumberは存在しない
2)私はoptio nはjarのエクスポートであり、私は今Maven BuildからJARを使用しようとしています。 私はビルドのMavenを使用して実行するにはPOMを選択し、それが
XYZ-0.0と第二に、別の16キロバイトで名前XYZ-0.0.1-SNAPSHOTとターゲットフォルダ内の2瓶、
1を作成しました。
が機能へのパスを手に入れたん:1-SNAPSHOT-ジャーとの依存関係私は
を使用して依存関係を持つ大きなファイルを実行した33メガバイト
1)とは、それは私にメッセージを与えましたディレクトリ
2)私はRunCukesTestファイルに名前空間を追加しようとしました。
java -jar xyz-0.0.1-SNAPSHOT-jar-with-dependencies.jar se.stepDefinations.RunCukesTest
私はエラーを受け取った:エラーが言うように、ターゲットフォルダ内の機能を発見しようとしているもちろん、ファイルやディレクトリは、
が見つかりません。
このように、実行可能ファイルのような他のコンピュータでも、プロジェクトファイルの依存関係に依存しないJARを実行したいとします。
ご協力いただければ幸いです。ありがとう。