java - 在所选项目中找不到测试类

标签 java junit automation cucumber gherkin

目前我正在开发一个使用 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 cucumber 文件:

功能:登录操作

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 测试运行时,我都会收到错误消息:

在所选项目中找不到测试类。

最佳答案

你应该指定 cucumber 功能文件:

@RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:cucumberTest/LogIn_Test.feature")
public class TestRunner {

}

确保你已经将它放在与包名相同路径下的资源文件夹中,即:workspace\project-name\src\test\resources\cucumberTest\

关于java - 在所选项目中找不到测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30782803/

相关文章:

java - 将一年添加到 java.util.Calendar 时出现奇怪的结果

java - HttpServletRequest - 如何获取引用 URL?

android - 在所有 junit 测试之前运行一次性异步回调

java - JUnit - 从类型转换返回模拟对象

java - 梯度下降的铰链损失最小化的正确实现

java - "Java concurrency in practice"- 缓存的线程安全数字分解器( list 2.8)

java - 正确放置线模的 Junit 测试类中的 stub

iOS UI 自动化 : toggle network settings during test execution time from within the tests

.net - 从 .Net 枚举另一个应用程序的 Windows/控件

android - SEND_SMS 十月政策更新