Can't run and debug groovy tests under intellij idea
Asked Answered
M

2

14

I try to embed groovy test to java project. I start with spock examples - https://github.com/spockframework/spock-example

Examples is compile and execute by running maven goal test but if i try to run test under intellij idea (ctrl+F10 under test method) it failure with classpath error.

Error running HelloSpockSpec.length of Spock's and his friends' names: Class 'HelloSpockSpec' not found in module 'spock-example'

I try to apply advices from IntelliJ + Groovy + Spock but it didn't help.

Madalena answered 1/7, 2015 at 14:36 Comment(2)
Is the folder marked as test sources?Gutierrez
You are right! I miss to do it. Thank you. If you right answer i will vote and mark it as complete.Madalena
G
28

Don't forget to mark the folder as "Test Sources" in IntelliJ

Then it should work as expected :-)

Gutierrez answered 1/7, 2015 at 14:54 Comment(1)
Just for in case... Right click on test/groovy folder -> Mark Directory as -> Test sources rootHers
K
5

Intellij can automatically add the groovy source as a source directory based on your pom. Add build-helper-maven-plugin config to your maven pom under plugins specifying ${basedir}/src/test/groovy as a source dir:

<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>
Kristenkristi answered 20/2, 2017 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.