【问题标题】:Can't run and debug groovy tests under intellij idea在 intellij idea 下无法运行和调试 groovy 测试
【发布时间】:2015-07-01 14:36:55
【问题描述】:

我尝试将 groovy 测试嵌入到 java 项目中。 我从 spock 示例开始 - https://github.com/spockframework/spock-example

示例是通过运行 maven 目标测试来编译和执行,但如果我尝试在 intellij idea 下运行测试(测试方法下的 ctrl+F10)它会失败并出现类路径错误。

运行 HelloSpockSpec.length 的 Spock 和他朋友的名字时出错: 在模块“spock-example”中找不到类“HelloSpockSpec”

我尝试应用来自 IntelliJ + Groovy + Spock 的建议,但没有帮助。

【问题讨论】:

  • 文件夹是否标记为测试源?
  • 你是对的!我想这样做。谢谢你。如果您回答正确,我将投票并将其标记为完成。
  • 完成!很高兴我能帮忙:-)

标签: intellij-idea groovy spock


【解决方案1】:

不要忘记在 IntelliJ 中将文件夹标记为“测试源”

然后它应该按预期工作:-)

【讨论】:

  • 以防万一...右键test/groovy文件夹 -> Mark Directory as -> Test sources root
【解决方案2】:

Intellij 可以根据你的 pom 自动将 groovy 源添加为源目录。将 build-helper-maven-plugin 配置添加到 plugins 下的 maven pom 中,指定 ${basedir}/src/test/groovy 作为源目录:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-groovy-test-source</id>
            <phase>test</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>${basedir}/src/test/groovy</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    相关资源
    最近更新 更多