【问题标题】:Test class not found in selected project在所选项目中找不到测试类
【发布时间】:2015-08-27 06:25:03
【问题描述】:

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

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

【问题讨论】:

    标签: java junit automation cucumber gherkin


    【解决方案1】:

    你应该指定黄瓜特征文件:

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

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

    【讨论】:

    • 我们将不胜感激,您也是 Viratan 吗?
    【解决方案2】:

    我知道这是我正在回答的一个较老的问题,但您似乎缺少 @CucumberOptions() 中的胶水选项:

    @CucumberOptions(
        features = "Feature"
        ,glue={"stepDefinition"}
        )
    

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      • 2015-08-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-27
      相关资源
      最近更新 更多