黄瓜微微容器未注册

cucumber-picocontainer not registering

我遇到了与 , but none of the suggested solutions work for me. Basically, I have taken a download of this repository 相同的情况。它运行良好。然后,我将 SearchSteps 模块一分为二——一个包含 @Before@After 语句,另一个包含步骤(因为我打算重用初始化代码)。我已将对 cucumber-picocontainer 的依赖添加到我的 pom.xml

我遇到了与上述问题相同的错误:class com.browserstack.stepdefs.SearchSteps doesn't have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath。我已经尝试了所有建议的解决方案,但错误仍然存​​在。

我的 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.browserstack</groupId>
    <artifactId>cucumber-jvm-java-browserstack</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>cucumber-jvm-java-browserstack</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <cucumber.jvm.parallel.version>2.2.0</cucumber.jvm.parallel.version>
        <surefire.maven.plugin.version>2.19.1</surefire.maven.plugin.version>
        <acceptance.test.parallel.count>1</acceptance.test.parallel.count>
    </properties>

    <dependencies>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
        </dependency>

        <dependency>
            <groupId>org.picocontainer</groupId>
            <artifactId>picocontainer</artifactId>
            <version>2.14.3</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>com.browserstack</groupId>
            <artifactId>browserstack-local-java</artifactId>
            <version>1.0.1</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire.maven.plugin.version}</version>
                <executions>
                    <execution>
                        <id>acceptance-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <forkCount>${acceptance.test.parallel.count}</forkCount>
                            <reuseForks>true</reuseForks>
                            <includes>
                                <include>**/*IT.class</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/test-classes/com/yourcompany/cucumberjvm</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/test/resources</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.temyers</groupId>
                <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                <version>${cucumber.jvm.parallel.version}</version>
                <executions>
                    <execution>
                        <id>generateRunners</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>generateRunners</goal>
                        </goals>
                        <configuration>
                            <!-- Mandatory -->
                            <!-- comma separated list of package names to scan for glue code -->
                            <glue>com.browserstack.stepdefs</glue>
                            <!-- These are the default values -->
                            <!-- Where to output the generated Junit tests -->
                            <outputDirectory>${project.build.directory}/generated-test-sources/features</outputDirectory>
                            <!-- The diectory containing your feature files.  -->
                            <featuresDirectory>src/test/java/resources/features</featuresDirectory>
                            <cucumberOutputDir>${project.build.directory}/cucumber_reports/test_results</cucumberOutputDir>
                            <!-- comma separated list of output formats -->
                            <format>junit</format>
                            <!-- CucumberOptions.strict property -->
                            <strict>true</strict>
                            <!-- CucumberOptions.monochrome property -->
                            <monochrome>true</monochrome>
                            <!-- The tags to run, maps to CucumberOptions.tags property -->
                            <tags>"~@ignore"</tags>

                            <namingScheme>pattern</namingScheme>
                            <!-- The class naming pattern to use.  Only required/used if naming scheme is 'pattern'.-->
                            <namingPattern>{f}_Parallel{c}IT</namingPattern>

                            <!-- If set to true, only feature files containing the required tags shall be generated. -->
                            <!-- Excluded tags (~@notMe) are ignored. -->
                            <filterFeaturesByTags>true</filterFeaturesByTags>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

依赖项显示在我的项目结构中。我究竟做错了什么?

如果需要,很乐意提供所有源代码。

上面@mpkorstanje 给出的答案是正确的。依赖全文如下,注意与所有 info.cukes artifacts 版本相同:

<dependency>
   <groupId>info.cukes</groupId>
   <artifactId>cucumber-picocontainer</artifactId>
   <version>1.2.5</version>
</dependency>