2014-02-12 93 views
6

試圖實施黃瓜做一些自動化測試。 jUnit測試。我創建了2個文件,並編輯了maven項目附帶的pom.xml文件來添加依賴項。內容如下所示。兩個文件中的第一個是黃瓜.feature文件,它是一種淺黃色的小黃瓜。另一個是CukesRunner.java黃瓜junit轉輪java.lang.NoSuchMethodError:

當我運行我的測試使用Project -> Run as ... -> Maven test它按預期工作。

然而,當我跑使用Eclipse在Eclipse的JUnit GUI的CukesRunner.java文件,我得到一個錯誤:

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description; 
    at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43) 
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77) 
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41) 
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226) 
    ... 

的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.bdd</groupId> 
    <artifactId>airportparking</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 

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

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

    <dependencies> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-java</artifactId> 
      <version>1.1.5</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>info.cukes</groupId> 
      <artifactId>cucumber-junit</artifactId> 
      <version>1.1.5</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.rubiconproject.oss</groupId> 
      <artifactId>jchronic</artifactId> 
      <version>0.2.6</version> 
      <scope>test</scope> 
     </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 
</project> 


CukesRunner.java:

package com.bdd.airportparking; 

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

@RunWith(Cucumber.class) 
@Cucumber.Options(
     format={"pretty", "html:target/cucumber"}, 
     features="src/test/resources" 
     ) 
public class CukesRunner { 

} 


ValetParking.feature:

Feature: Valet Parking 
    As a traveler 
    In order to determine where to park my car 
    I want to know the cost of valet parking 

Scenario: Calculate valet parking cost for half an hour 
    When I park my car in the Valet Parking Lot for 30 minutes 
    Then I will have to pay $12 


輸出運行CukesRunner.javaJunit Test時:

java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description; 
    at cucumber.runtime.junit.FeatureRunner.getDescription(FeatureRunner.java:43) 
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:77) 
    at cucumber.api.junit.Cucumber.describeChild(Cucumber.java:41) 
    at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:226) 
    at org.junit.runner.Runner.testCount(Runner.java:38) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.countTestCases(JUnit4TestClassReference.java:30) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.countTests(RemoteTestRunner.java:487) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:455) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 


如何構建我的Eclipse項目: http://postimg.org/image/vf6tlw7el/full/

+0

你在哪裏有'stepdefs'? – Bala

+0

@Bala它應該在哪裏? – Onizuka

+0

檢查這個答案。它可能會幫助你。 http://stackoverflow.com/questions/21753267/cucumber-jvm-undefined-step/21754450#21754450 – Bala

回答

11

更新你的junit版本,也許你的surefire插件將解決這個問題。

 <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.11</version> 
      <scope>test</scope> 
     </dependency> 

對於神火:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.16</version> 
     </plugin> 
    </plugins> 
</build> 
1

不同的故事,但同樣的問題......發展詹金斯插件,使用gradle這個,有最新的junit:junit:4.12庫在我的類路徑...

問題是由junit:junit-dep:4.10庫引起的,「又名」...

<dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit-dep</artifactId> 
    <version>4.10</version> 
    <scope>test</scope> 
</dependency> 

從我的配置類路徑中明確刪除它後,我不再有問題。

0

我面臨同樣的問題,我發現我在我的構建路徑中配置了junit 4.10和4.11,堅持junit 11,解決了這個問題。

0
<dependencies> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-java</artifactId> 
     <version>1.2.2</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-junit</artifactId> 
     <version>1.2.2</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.github.mkolisnyk</groupId> 
     <artifactId>cucumber-reports</artifactId> 
     <version>0.0.11</version> 
    </dependency> 
</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.2</version> 
      <configuration> 
       <encoding>UTF-8</encoding> 
       <source>1.6</source> 
       <target>1.6</target> 
       <compilerArgument>-Werror</compilerArgument> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
+0

我已經更新了我的POM,如下所示,並得到解決。 –