Grails 2.4.3集成测试错误java.lang.NoClassDefFoundError:org / springframework / mock / web / MockAsyncContext

时间:2016-07-07 16:42:27

标签: hibernate grails integration-testing spock

我正在使用旧版Oracle 10g数据库处理Grails应用程序(v 2.4.3),并在尝试对服务运行集成测试时遇到以下错误。我在谷歌和这里搜索过,在服务集成测试期间找不到其他人收到此错误。我的单元测试运行没有问题的域类,我只有集成测试这个错误。

该应用程序的结构是在服务层中调用所有hibernate条件,并且不能将它们放在域类中。

Running 1 integration test...
| Running 1 integration test... 1 of 1
| Failure:  test getAllDeliveryTypes(catalog.CatalogServiceSpec)
|  java.lang.NoClassDefFoundError: org/springframework/mock/web/MockAsyncContext
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
        at java.lang.Class.getDeclaredMethods(Class.java:1967)
        at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
        at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
        at grails.test.spock.IntegrationSpec.initRequestEnv(IntegrationSpec.groovy:96)
        at grails.test.spock.IntegrationSpec.setup(IntegrationSpec.groovy:62)
Caused by: java.lang.ClassNotFoundException: org.springframework.mock.web.MockAsyncContext
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        ... 6 more
| Completed 1 integration test, 1 failed in 0m 0s

集成测试类

package catalog

import grails.test.spock.IntegrationSpec
import spock.lang.*

/**
 *
 */
class CatalogServiceSpec extends IntegrationSpec {

    static DeliveryType deliveryType
    static CatalogService catalogService = new CatalogService()

    def setup() {
        deliveryType = new DeliveryType()
        deliveryType.id = 1
        deliveryType.createdById = 101
        deliveryType.createdOn = new Date()
        deliveryType.modifiedById = 101
        deliveryType.modifiedOn = new Date()
        deliveryType.code = '01'
        deliveryType.name = 'In-Person Classroom'
    }

    @Unroll("test getAllDeliveryTypes")
    def "test getAllDeliveryTypes"() {


        when:
        def results = catalogService.getAllDeliveryTypes()

        then:
        results.size() == 1

    }
}

服务类

package catalog

import grails.transaction.Transactional

@Transactional
class CatalogService {

    List<DeliveryType> getAllDeliveryTypes() {        

        List<DeliveryType> deliveryTypes = DeliveryType.list(sort: "id", order: "asc")        

        return deliveryTypes
    }  
}

package catalog

class DeliveryType {

    static constraints = {
        id range: 1..2500000000
        createdById range: 1..2500000000
        modifiedById range: 1..2500000000
        code maxSize: 6, unique: true
        name maxSize: 30
    }

    static mapping = {
        version false
        table name: 'delivery_type', schema: 'catalog'
        id generator:'assigned'
    }

    Long id
    Long createdById
    Date createdOn
    Long modifiedById
    Date modifiedOn
    String code
    String name
}

配置文件

    dependencies {            
        test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
        runtime 'org.springframework:spring-test:3.1.0.RELEASE'
    }

    plugins {
        // plugins for the build system only
        build ":tomcat:7.0.55"

        // plugins for the compile step
        compile ":scaffolding:2.1.2"
        compile ':cache:1.1.7'
        compile ":asset-pipeline:1.9.6"

        // plugins needed at runtime but not for compilation
        runtime ":hibernate4:4.3.5.5" // or ":hibernate:3.6.10.17"
        runtime ":database-migration:1.4.0"                
    }

非常感谢。

布雷特

1 个答案:

答案 0 :(得分:0)

删除@Unroll,因为您的规范中没有位置:

在设置阶段,您不会提交创建的deliveryType。该服务来自DeliveryType.list(),所以如果它没有提交,它就不会被拉入响应。

最后,您的dataSource是否正确设置了测试环境?

相关问题