我已经在Java中设置了一个 Cucumber 项目,在Eclipse IDE中,我可以直接运行功能文件,并且测试将完成。但是,当我将它们作为JUnit测试运行时,它们没有运行,在控制台中,它们显示为
@When("^user navigates to Login Page$")
public void user_navigates_to_Login_Page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
如果我双击“ JUnit”选项卡中的步骤,则会收到以下消息
“在所选项目中找不到测试类”
我的测试跑步者班级看起来像这样,
package com.bsautoweb.runner;
import java.io.File;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(glue = {"src/test/java/com/bsautoweb/stepdefinitions"}, features = {"src/test/resources/features/"},
plugin = "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html",
monochrome = true
)
public class Testrunner {
@AfterClass
public static void writeExtentReport() {
Reporter.loadXMLConfig(new File("config/report.xml"));
}
}
我的文件夹结构如下所示
看来JUnit忽略了我的粘合代码。即使输入无效路径,也不会抱怨。
将胶水选项设置为com/bsautoweb/stepdefinitions
或Java包样式com.bsautoweb.stepdefinitions
这是正确的答案。Java包样式可能更好一点,因为它强调它不是项目中的文件夹,而是名称空间。