微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Project无法识别cucumber-picocontainer依赖项

我目前正在研究一个带有cucumber,JUnit和Selenium的java测试框架.我已经在这样的项目上工作了,但是我遇到了这个问题.

我正在尝试创建一个Singleton的Context类.我想使用cucumber-picocontainer在每个步骤定义类中都可以访问此类.我在我的pom.xml中添加了依赖项,但每次我尝试执行我的测试时,我都有一个例外:“NewLoginSteps没有空的构造函数.如果你需要DI,请在类路径上放置cucumber-picocontainer” .我试图手动导入罐子,但它没有帮助.

以下是我的配置示例:

> pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>


    <properties>
        <cucumber.version>1.2.4</cucumber.version>
        <selenium-java.version>2.39.0</selenium-java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
</project>

TestContext.java:

public class TestContext {
    private static Map<String, String> siteLocations = new HashMap<String, String>();
    private static boolean initialized = false;
    private static boolean firstinitDone = false;
    private static WebDriver driver;
    private static boolean testsToRun = false;
    private static AutomatedTestMode modeAsEnum;

    @Before
    public void setUp(Scenario scenario) {
        initialize();
        Log.startTestCase(scenario.getName());
        afterall();
    }
    ....
}

步骤定义类:

public class NewLoginSteps extends NewSuperSteps {

    public NewLoginSteps(TestContext context){
        super(context);
    }


    @When("^I log in nova as \"([^\"]*)\" user with \"([^\"]*)\" \"([^\"]*)\"$")
    public void newLogin(String instance, String username, String password){
        Assert.assertEquals(true, false);

    }

    @Then("^The user is connected$")
    public void The_user_is_connected(){
        throw new PendingException();
    }

}

我的superSepts类:

public class NewSuperSteps {
    protected TestContext context;
    public NewSuperSteps(TestContext context){
        this.context=context;
    }

}

你知道我做错了什么吗?我已经使用了picocontainer来做同样的事情并且它正在工作.

解决方法:

我遇到了类似的问题.

问题出在info cukes的版本中.你需要在你的pom.xml中拥有相同版本的所有cucumber- *.
 这解决了我的问题.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐