问题描述
我有一个 maven
项目来运行 cucumber
和 selenium
. *.feature
文件在 src/features
中定义,步骤在 src/test/java/com/example/steps 中定义代码>.
I have a
maven
project to run cucumber
and selenium
. The *.feature
files are defined in the src/features
, and the steps are defined in the src/test/java/com/example/steps
.
我还定义了一个测试运行器类,如下所示:
I have also defined a test runner class as below:
package com.example.runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(
features={"src/features"},
glue="com/example/steps")
public class RunnerTest {
}
问题是:我在上课时抱怨:
Class not found com.example.runner.RunnerTest
java.lang.ClassNotFoundException: com.example.runner.RunnerTest
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:688)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
问题是,为什么无法识别跑步成绩?
更新:
当我通过
打开功能文件->右键单击->运行方式-> 1个黄瓜功能
效果很好
我将
glue ="com/example/steps"
更改为 glue ="com.example.steps"
,它抱怨:
java.lang.NullPointerException
at com.example.steps.Click_Steps.i_am_in(Click_Steps.java:23)
at ✽.Given I am in "http://suvian.in/selenium/1.6checkbox.html"(CheckBox.feature:14)
当我引用文件时:
base.getDriver().navigate().to(uri);
但是正如我所说,当我使用
Run as->运行功能文件时,此行效果很好.黄瓜
But as i said, this line work pretty well when i run the feature file using
Run as -> Cucumber
推荐答案
我会考虑通过以下方式重新组织您的结构:
I would consider re-organizing your structure in the following way:
src/
├── main/
│ └── java/
| └── ...
│
└── test/
├── java/
| └── com.example/
| ├── checkbox/
| | ├── CheckboxSteps/
| | └── CheckboxTest/
| ├── click_button/
| | ├── ClickButtonSteps/
| | └── ClickButtonTest/
| └── ...
|
└── resources/
└── features/
├── checkbox/
| └── checkbox.feature/
├── click_button/
| └── ClickButton.feature/
└── ...
如果测试失败,这将改善代码的组织和可追溯性.
This will improve both your code organization and traceability in case of failing tests.
CheckboxTest
随后应如下所示:
package com.example.checkbox;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
snippets = SnippetType.CAMELCASE,
glue = {"com.example.checkbox"},
features = "classpath:features/checkbox")
public class CheckboxTest {
/*
* This class should be empty, step definitions should be in separate classes.
*/
}
然后将您的步骤定义放在
CheckboxSteps
中.
Then put your step definitions in
CheckboxSteps
.
您现在应该可以运行
CheckboxTest
.
这篇关于黄瓜:找不到类com.example.runner.RunnerTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!