目前我正在开发一个使用Cucumber的简单程序,它将测试网站上用户的登录情况。
这是我的TestRunner文件:
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features = "Feature")
public class TestRunner {
}
我还将黄瓜文件作为LogIn_Test.feature,如下所示:
功能:登录操作
Scenario: Successful Login with Valid Credentials
Given User is on Home Page
When User Navigate to LogIn Page
And User enters UserName and Password
Then Message displayed Login Successfully
Scenario: Successful LogOut
When User LogOut from the Application
Then Message displayed LogOut Successfully
但每当我尝试将TestRunner类作为JUnit测试运行时,我都会收到错误:
在所选项目中找不到测试类。
答案 0 :(得分:2)
你应该指定黄瓜特征文件:
@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:cucumberTest/LogIn_Test.feature")
public class TestRunner {
}
确保您已将其放置在与包名称相同的路径下的资源文件夹中,即:workspace\project-name\src\test\resources\cucumberTest\
答案 1 :(得分:0)
我知道这是一个较旧的问题我正在回复,但您似乎错过了@CucumberOptions()中的胶水选项:
@CucumberOptions(
features = "Feature"
,glue={"stepDefinition"}
)