2

我想將我的驗收測試打包到可執行JAR中,其中包含運行測試和生成報告所需的全部庫。我還想要運行所有測試或單個測試。從可執行文件運行一個黃瓜方案JAR

到目前爲止,我可以運行所有測試,並且雖然報告正在我在serenity.properties中指定的位置生成,但index.html並未生成。

通常情況下,我會使用maven驗證目標運行我的測試,該目標將運行serenity-maven-plugin,但由於我從JAR運行,我不知道如何實現同樣的目標。

我有一個主類,如下所示:

@RunWith(CucumberWithSerenity.class) 
@CucumberOptions(features = "classpath:com/cfhayes/test/LookupADefinition.feature") 
public class DefinitionTestSuite { 
    public static void main(String[] args) throws Exception { 
    JUnitCore.main("com.cfhayes.test.DefinitionTestSuite"); 
    } 
} 

而且我有文件使用的標籤,這樣我可以指定一個可運行的情景:

Feature: Lookup a definition 

    @TEST-0001 
    Scenario: Looking up the definition of 'apple' 
    Given the user is on the Wikionary home page 
    When the user looks up the definition of the word 'apple' 
    Then they should see the definition 'A common, round fruit produced by the tree Malus domestica, cultivated in temperate climates.' 

    @TEST-0002 
    Scenario: Looking up the definition of 'pear' 
    Given the user is on the Wikionary home page 
    When the user looks up the definition of the word 'pear' 
    Then they should see the definition 'An edible fruit produced by the pear tree, similar to an apple but elongated towards the stem.' 

我希望有是我可以使用JVM參數與可執行文件JAR的一種方式,它可以讓我設置黃瓜選項。我試着做這樣的事情:

java -jar my-test-jar.jar -Dcucumber.options="--tags @TEST-0001" 

...但仍然運行所有測試。

任何想法將不勝感激。

+0

正是我現在需要的。你有沒有想出任何解決方案? – yuva

+1

是的,我遇到的問題只是命令行參數的順序。這裏是我必須使用的命令行: java -Dcucumber.options =「 - tags @ TEST-0001」-jar my-test-jar.jar 無需其他更改。 – cfhayes

+1

下面是一個可以看一看的工作示例: https://github.com/ch88251/cucumber-serenity-example – cfhayes

回答

2

構建命令的方式可能不正確。黃瓜選項被視爲com.cfhayes.test.DefinitionTestSuite::main的參數,而不是java選項。試試這個:

java -Dcucumber.options="--tags @TEST-0001" -jar my-test-jar.jar 

或者在你的班級中處理黃瓜選項。

+0

嗨米科拉,你的建議工作完美。非常感謝你的幫助! – cfhayes

+0

您可能想要通過接受我的答案來結束該問題。 –

相關問題