Java プロジェクトをテストするために Cucumber を追加しようとして、機能ファイルを作成しました。
Feature: I visit the website
Scenario: I read the home page
Given I am on the "home" page
cukesを実行するクラスを書きました
import cucumber.api.CucumberOptions;
/**
* See https://cucumber.io/docs/reference/jvm#junit-runner
*/
@RunWith(Cucumber.class)
@CucumberOptions(glue = {"classpath:stepdefinitions"},features = {"src/test/features"})
public class RunCukesTest {
}
そして、ステップ定義: (ここに注釈が欠けていると感じています)
package com.myproject.test.stepdefinitions;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
public class WebSteps implements En {
public WebSteps() {
Given("^I am on the \"([^\"]*)\" page$", (String page) -> {
System.out.println(page);
});
}
}
だから私が何を入れてもglue = {}
、ステップは見つかりません。glue = {"classpath:stepdefinitions"}
またはテストが緑色で、「以下のスニペットを使用glue = {"stepdefinitions"}
して不足している手順を実装できます」というメッセージが表示されます (手順が見つかりません)。完全なパッケージパスを入力すると、glue = {"com.myproject.test.stepdefinitions"}
またはglue = {"classpath:com.myproject.test.stepdefinitions"}
スタック トレースがあります。
java.lang.NoClassDefFoundError: org/springframework/test/context/ContextHierarchy
at cucumber.runtime.java.spring.SpringFactory.annotatedWithSupportedSpringRootTestAnnotations(SpringFactory.java:198)
at cucumber.runtime.java.spring.SpringFactory.dependsOnSpringContext(SpringFactory.java:187)
at cucumber.runtime.java.spring.SpringFactory.addClass(SpringFactory.java:61)
at cucumber.runtime.java.JavaBackend.loadGlue(JavaBackend.java:96)
at cucumber.runtime.Runtime.<init>(Runtime.java:91)
at cucumber.runtime.Runtime.<init>(Runtime.java:69)
at cucumber.runtime.Runtime.<init>(Runtime.java:65)
at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78)
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.springframework.test.context.ContextHierarchy
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 26 more
ここに私が追加したものがありますpom.xml
:
<!-- Tests with cucumber -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java8</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<!-- Dependency Injection with Spring https://cucumber.io/docs/reference/java-di#spring -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<!-- JUnit Runner : https://cucumber.io/docs/reference/jvm#running -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
私のプロジェクトでは Spring 4 を使用しています。