2016-08-02 110 views
0

我想在黄瓜中使用testNG框架。但得到低于错误。org.testng.testngexception can not instantiate class cucmber-testng error

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 
[INFO] BUILD FAILURE 
[INFO] Total time: 8.032 s 
[INFO] Finished at: 2016-08-02T16:11:29+05:30 
[INFO] Final Memory: 18M/220M  
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project TestCaseAPI: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test failed: There was an error in the forked process 
[ERROR] org.testng.TestNGException: 
[ERROR] 
[ERROR] Cannot instantiate class com.XXX.automation.feature.RunCuke1Test 
[ERROR] at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40) 

我的亚军类如下:

import org.junit.runner.RunWith; 
    import cucumber.api.CucumberOptions; 
    import cucumber.api.junit.Cucumber; 
    import cucumber.api.testng.AbstractTestNGCucumberTests; 
    @RunWith(Cucumber.class) 
    @CucumberOptions (features = "src/test/resources/feature" 
    ,glue="com.XXX.automation.feature" 
    ,monochrome=true 
    ) 
    public class RunCuke1Test extends AbstractTestNGCucumberTests {  
    } 

我的testng.xml就像下面

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite"> 
<test name="Test diary"> 
<classes> 
<class name="com.XXX.automation.feature.RunCuke1Test"/> 
</classes> 
</test> 
</suite> 

我的项目结构如上: enter image description here

我通过Maven运行它

任何人都可以告诉我我在做什么错吗?

+1

您正在混合testng和junit测试:从删除'@RunWith(Cucumber.class)'开始' – juherr

+1

检查来自https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator -testng – juherr

+0

你不能使用TestNG黄瓜。使用Junit来执行Cucumber类。 –

回答

1

我做了对cucumber-testNG maven dependency的重新检查。早些时候我使用旧版本。我现在正在使用最新版本,现在我的程序已经成功运行。