2016-01-13 32 views
7

我對Cucumber/Maven有點新,所以需要運行測試用例的幫助。 我使用Cucumber和Selenium在eclipse中開發了一個自動化套件。要運行特定的功能文件/ Junit runner類,請右鍵單擊Eclipse中的文件並運行它。如何通過命令提示符並通過jenkins使用Maven運行單個黃瓜功能文件?

但是,如何通過命令提示符或詹金斯運行它,通過提供特定命令來運行2-3個功能文件(或)2-3個Junit跑步者課程,比如說50個功能文件或JUnit類?

下面是我如何在Eclipse中構建的包瀏覽器。

enter image description here

下面是pom.xml中

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.perspecsys</groupId> 
    <artifactId>salesforce</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>salesforce</name> 
    <url>http://maven.apache.org</url> 

    <properties> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 


    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-java</artifactId> 
      <version>1.1.2</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-picocontainer</artifactId> 
      <version>1.1.2</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-junit</artifactId> 
      <version>1.1.2</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-java</artifactId> 
      <version>2.48.2</version> 
     </dependency> 

    </dependencies> 
</project> 

回答

8

您可以運行使用cucumber.options單一特徵文件,該文件將覆蓋所有你在@CucumberOptions標註有選擇:

mvn test -Dcucumber.options="src/test/features/com/perspecsys/salesforce/featurefiles/Account.feature" 
+0

感謝您的幫助。該命令在命令提示符下工作。但是,我如何在Jenkins中配置相同的?我只想運行包com.perspecsys.salesforce.featurefiles,以便所有功能文件都在其下執行。你能幫我在詹金斯一步一步的配置嗎? – Ronnie

2

鑑於您正在使用Maven,並且您已經爲每個功能單獨安裝了一個跑步者類,您可以使用Failsafe插件或Surefire插件可以像這樣從命令行傳遞參數,並選擇要運行的運行程序。

故障安全版本:

-Dit.test=Account*Test,Login*Test 

神火版本:

-Dtest=Account*Test,Login*Test 

注意,您可以使用通配符,通過以逗號分隔的測試列表,並通過包引用完整位置和過濾器。

-Dit.test=com.perpecsys.salesforce.*Test 

爲此,我通常會使用故障安全插件,如黃瓜測試一個更像集成測試(終端到終端的測試真的),這是該插件是什麼,而神火插件旨在運行單元測試。

兩個插件的更多信息:

http://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html

http://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

從詹金斯它是完全一樣的,只是使用Maven項目插件來創建一個新的Maven項目,並在Build部分,根據目標和選項字段指定的maven命令如:

clean verify -Dit.test=Account*Test 

https://wiki.jenkins-ci.org/display/JENKINS/Maven+Project+Plugin

另外,只需添加如果你不使用Maven項目插件調用頂級行家目標一步生成,並添加選項那裏。

希望這會有所幫助。

2

如果你希望它硬編碼的,你可以這樣做:

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

@RunWith(Cucumber.class) 
@CucumberOptions(
     features={"src/test/resources/features/belly.feature"} 
     ,glue = "steps" //whatever the name of your steps package is 
     ) 
public class RunCukesTest 
{ 
} 
相關問題