简体   繁体   中英

Eclipse cannot find groovy class for Spock/Junit test

I am working on using spock in eclipse, and when trying to run tests I had successfully run in intelliJ I came across an issue. I had named my class different then my file name and so eclipse is unable to run a junit test and instead gives this error: 在此处输入图片说明 "The Input type of the launch configuration does not exist."

After some googling I got no where and decided to play around and found that if I executed all the test it would run fine, and even when I changed the class name to match the filename it would work. Is there a way to configure eclipse/junit to be able to run a test on a groovy class that does not match the file name?

HelloWorld.groovy:

import spock.lang.*

class MyFirstSpockTest extends spock.lang.Specification {

def "length of Spock's and his friends' names"() {
    expect:
    name.size() == length

    where:
    name     | length
    "Spock"  | 5
    "Kirk"   | 4
    "Scotty" | 6
}

def "basic test"() {
    expect:
    Math.min(a, b) == c

    where:
    a | b || c
    3 | 7 || 7   // Will fail here
    5 | 4 || 4   // Will pass
    9 | 9 || 9   // Will pass
}

def "persons name tells you gender"() {
    expect:
    person.getGender() == gender

    where:
    person                    || gender
    new Person(name: "Fred")  || "Male"
    new Person(name: "Wilma") || "Female"
}

static class Person {
    String name

    String getGender() {
        name.equals("Fred") ? "Male" : "Female"
    }
}
}

The root of both your main code tree and test code tree need to be in the classpath settings. To do this, in the Package Explorer window, right click on the Project name, select "Build Path" from the menu, then select "Configure Build Path", select the Source tab and make sure both your main code and test code directories are listed. If the test code directory is not listed, add it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM