黄瓜jvm CucumberException:[]没有找到任何功能

时间:2013-01-21 11:32:12

标签: cucumber cucumber-jvm cucumber-junit

在我的黄瓜-jvm,Maven,junit设置中我将testRunner文件作为

package com.lebara.testrunner;

import cucumber.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(

glue = {"com.lebara.stepdefs","com.lebara.framework.main", "com.lebara.testrunner"},
features = "C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources",
format = {"pretty", "html:target/cucumber-html-report", "json-pretty:target/cucumber-report.json"},
tags = {"@UserJourney"}

)
public class RunCukesTest {
}

我在上面提到的目录中有我的功能文件。

如果我运行它,我会得到以下异常:

cucumber.runtime.CucumberException: No features found at [C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources/cucumber]...

如果删除testrunner中的“features”选项,它会尝试在与我的testrunner.java相同的目录中查找要素文件

cucumber.runtime.CucumberException: No features found at [com/lebara/testrunner]

如果我把功能文件放在那里,它就可以了。

我的问题是为什么我的功能文件没有从我之前的位置拾取,我认为这是黄瓜 - maven设置的默认文件结构。

如何从那里取货?帮助赞赏。

9 个答案:

答案 0 :(得分:15)

您的测试运行器和功能文件到底在哪里?我有以下设置,它完美无缺:

src/test/
    java/
        com/mypackage/
            TestRunner.java
            StepDefinition.java
    resources
        com/mypackage/
            fancy.feature

Maven / Cuke约定将从tests / java目录和test / resources目录中的功能文件执行测试。我的测试运行器与您的测试运行器基本相同,但选项较少:

import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"pretty"})
public class TestRunner { }

希望如果您还没有找到答案,这会有所帮助。

答案 1 :(得分:4)

我有类似于你的设置(不使用Maven / Cucumber约定)。在我的选项中,我没有指定从root开始的路径,而是从项目的源文件夹中指定功能。这是有道理的,因为否则测试只能在你的机器上运行。

在你的情况下,我认为它应该是:

features = "src/main/resources"

答案 2 :(得分:3)

只需添加要点= {" classpath:features / feature.feature"},该功能必须位于 test / resources / features / feature.feature 下。

    @CucumberOptions(
        format = {"pretty", "html:target/html"},
        features = {"classpath:features/feature.feature"},
        snippets = SnippetType.CAMELCASE

注意 classpath

当您使用maven打开目标/测试类/功能编译代码时,您会看到 feature.feature

答案 3 :(得分:3)

//Removing the space between "**classpath**" and "**:com/**" helped.

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"classpath:com/tk/feature/"}, //NOTE: NO SPACE
        glue = {"classpath: com.tk.cucumber"}, 
        plugin = {
                "pretty", 
                "html:build/reports/cucumber" 
                ,"json:build/reports/cucumber-tests/test.json"}
        )
public class RunAPITests {}

答案 4 :(得分:0)

如果要提供要素文件的完整路径,即

“C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources”,如您的查询中所示,将'/'字符替换为'\\'再次尝试(双反斜杠) )如下。

“C:\\ Users \\ sarthak.dayanand \\ Documents \\ WebRefreshTest \\ CukeAutomation \\ LebaraWebAutomationTest1 \\ src \ main \\ resources \\ abc.feature”

答案 5 :(得分:0)

这是一个使用最新黄瓜版本的git repo:Cucumber- Example

克隆此存储库,然后在本地计算机上运行它。 warning: the lock file is not up to date with the latest changes.... nothing to install or update. 已定义并且应该通过。 @Given@Then应该显示为未定义。

这是其输出的外观: Output for the Belly feature

使用上述结构: @When {步骤定义Java并在此处运行黄瓜测试文件} src / test / java/ io /cucumber / {此处提供功能文件}

您可以使用src /test / resources/ io/ cucumber /运行gradle构建 和使用./gradlew clean build

进行的黄瓜测试

如果可行,则在项目中使用相同的格式。

答案 6 :(得分:0)

只需将 .F 特征更改为 .f 特征即可为我解决问题。

还要确保按照功能文件夹在 CucumberOptions 中正确提及功能的路径

一些在线教程中提到过。 F 特性带来了这个问题

因此更改大小写将解决此问题

enter image description here

答案 7 :(得分:0)

在另一个实例中,发生“找不到功能”错误。由于没有类似的问题,我正在此答案下发布解决方案。

在Maven中设置Cucumber项目后,第一次尝试运行Runner文件时遇到此错误。我找到的解决方案如下:转到Windows资源管理器中“功能”文件所在的文件夹。检查您要运行的功能文件的大小。如果大小为“ 0” KB,它将显示“未找到功能”错误。对文件进行一些更改,直到显示一个大于零的值。进行更改后再次运行。

答案 8 :(得分:-3)

将功能文件放在 src / test / java 下的跑步者和步骤文件或 将它放在 src / main / java 下,问题就会得到解决。

随时欢迎谢谢。:)

相关问题