2013-01-21 136 views
5

發現在我的黃瓜-jvm,Maven的功能,JUnit的設置,我有我的TestRunner文件黃瓜JVM CucumberException:沒有爲[]

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的「功能」選項,它會嘗試查找功能文件在同一目錄作爲我testrunner.java

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

如果我把這些功能文件放在那裏,它就可以工作。

我的問題是爲什麼我的功能文件沒有被從我以前的位置拾取,我認爲這是黃瓜 - maven設置的默認文件結構。

如何使它從那裏接?幫助讚賞。

回答

12

您的測試跑步者和功能文件究竟在哪裏?我有以下設置,其中工程完美:

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

行家/黃瓜公約將有來自測試/ java目錄執行的測試,並在測試/資源目錄中的功能文件。我的測試運行是基本一樣的你,但用更少的選擇:

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

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

希望這有助於你不是已經找到了答案。

+1

從「■特徵」,以改變」 .feature 「爲我修好了;謝謝 – ash

3

我有一個類似於你的設置(不使用Maven/Cucumber約定)。在我的選項中,我沒有指定從根目錄開始的路徑,而是從保存要素的項目源文件夾中指定路徑。這很有意義,否則測試只能從您的機器運行。

在你的情況,我覺得應該是:

features = "src/main/resources" 
0

如果您提供的特徵文件的完整路徑,即

「C:/Users/sarthak.dayanand/Documents/WebRefreshTest/CukeAutomation/LebaraWebAutomationTest1/src/main/resources「,如下所示,用'\\'替換'/'字符(雙斜槓)。

「C:\\用戶\\ sarthak.dayanand \\文獻\\ WebRefreshTest \\ CukeAutomation \\ LebaraWebAutomationTest1 \\ SRC \主\\資源\\ abc.feature」

1

只需添加功能= { 「classpath:features/feature.feature」},該功能必須在test/resources/features/feature.feature之下。

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

類路徑

當你編譯你的代碼,如果你使用maven打開目標/測試類/功能,你會看到功能。功能

-2

通過將功能下的文件的src/test/java下在亞軍和步驟文件或 通過將其下的src/main/java的問題將得到解決。

隨時歡迎您的感謝爲:)

+0

請勿將測試代碼放在** src/main **下。該文件夾通常包含用於生產的代碼,並且您不希望測試代碼進入生產。 – neXus

0

保持你的項目的結構如下,和它運作良好。

enter image description here