在groovy java混合项目中编写spock测试时无法解析类

时间:2015-06-15 05:21:31

标签: groovy gradle classpath spock

java8 gradle2.3 groovy2.4.3

 sourceSets {
        main {
            java { srcDirs = [] }    // no source dirs for the java compiler
            groovy { srcDir "src" }  // compile everything in src/ with groovy
        }
        test{
            java {srcDirs = []}
            groovy{ srcDirs = ["src/test/java", "src/test/groovy"] }
        }
    }

ControllerServiceSpec.groovy:18:无法解析类org.springframework.test.web.servlet.MockMvc

import info.thecodinglive.controller.TeamController
import info.thecodinglive.service.TeamService
import org.junit.runner.RunWith
import org.spockframework.runtime.Sputnik
import org.springframework.test.web.servlet.MockMvc
import spock.lang.Specification
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.http.HttpStatus.*

@RunWith(Sputnik)
class ControllerServiceSpec extends Specification{

    def teamController = new TeamController()
    def teamService = Mock(TeamService)

    MockMvc mockMvc = standaloneSetup(teamController).build()

    def setup(){
        teamController.teamService = teamService
    }

依赖

 {compile 'org.codehaus.groovy:groovy-all:2.4.3'
  testCompile group: 'junit', name: 'junit', version:'4.12'
    testCompile group: 'org.springframework', name: 'spring-test', version:"$springVersion"
    testCompile group: 'org.springframework', name: 'spring-test-mvc', version:'1.0.0.M1'
    testCompile  "cglib:cglib-nodep:3.1"
    testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
       exclude group: "org.codehaus.groovy"
    }

它可以编译groovy / java但是当我测试控制器时 找不到依赖

0 个答案:

没有答案