无法在Groovy项目上使用build-helper-maven-plugin运行测试

时间:2018-09-26 11:54:08

标签: maven spock build-helper-maven-plugin

我在Eclipse中有一个常规项目。我必须从Gradle更改为Maven,现在我无法运行其中存在的测试。

这是项目的结构:

enter image description here

这是pom.xml的内容:

    <dependencies>
    ...
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.0-groovy-2.4</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <compilerId>groovy-eclipse-compiler</compilerId>
                <compilerArguments>
                    <indy />
                    <!-- optional; supported by batch 2.4.12-04+ -->
                ...
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.12</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    ...
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/groovy</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

但是,如果我执行mvn全新安装,则测试不会运行。 这是控制台的输出:

enter image description here

1 个答案:

答案 0 :(得分:0)

我们拥有的测试用例称为Spec而不是Test,它是这样固定的:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <configuration>
                <includes>
                    <include>**/*Spec.class</include>
                </includes>
            </configuration>
        </plugin>