Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Grails中为作为REST资源的域类编写集成测试?_Rest_Grails_Resources_Integration Testing_Grails Domain Class - Fatal编程技术网

如何在Grails中为作为REST资源的域类编写集成测试?

如何在Grails中为作为REST资源的域类编写集成测试?,rest,grails,resources,integration-testing,grails-domain-class,Rest,Grails,Resources,Integration Testing,Grails Domain Class,我使用域类作为rest资源,如中所述 因此,在使用这种方法时,没有创建控制器或服务类。我试图找到一种方法,将域作为REST资源编写集成测试,但没有找到。因此,请告诉我如何做,或张贴一个链接到某个地方,告诉相同的 关于这个方法,这正是我要做的,所以我不能改变使用REST服务的其他方式 谢谢。 你应该考虑使用斯波克作为你的测试框架: 示例如何将其用于REST: class ExampleWebAppSpecification extends Specification { def "Sho

我使用域类作为rest资源,如中所述

因此,在使用这种方法时,没有创建控制器或服务类。我试图找到一种方法,将域作为REST资源编写集成测试,但没有找到。因此,请告诉我如何做,或张贴一个链接到某个地方,告诉相同的

关于这个方法,这正是我要做的,所以我不能改变使用REST服务的其他方式


谢谢。

你应该考虑使用斯波克作为你的测试框架:

示例如何将其用于REST:

class ExampleWebAppSpecification extends Specification {
    def "Should return 200 & a message with the input appended"() {

        setup:
             def primerEndpoint = new RESTClient( 'http://localhost:8080/' )
        when:
             def resp = primerEndpoint.get([ path: 'exampleendpoint', query : [ input : 'Get a hair cut' ]])
        then:
             with(resp) {
                 status == 200
                 contentType == "application/json"
             }
             with(resp.data) {
                 payload == "Something really important: Get a hair cut"
             }
    }
}
编辑- 在buildConfig.groovy中:

compile("org.codehaus.groovy:groovy-all:2.2.0")
compile("com.fasterxml.jackson.core:jackson-databind")

testCompile("org.spockframework:spock-core:0.7-groovy-2.0")
testCompile("org.codehaus.groovy.modules.http-builder:http-builder:0.7+")
testCompile("net.sf.json-lib:json-lib:2.4+")

谢谢你的回复。你能告诉我安装了哪些导入和插件吗?因为这个RESTClient类在默认情况下不可用。请将它添加到buildConfig.groovy:
compile:restclientbuilder:2.0.3“
Yes事实上我在检查google之后就这么做了。但是有一个问题,即使在搜索了很多之后,仍然没有解决,那就是当我在buildConfig中添加这个并运行应用程序来安装它时。尽管如此,它还是用红色下划线显示了错误-
Groovy:无法解析类RESTClient
甚至很少有人建议使用
导入grails.plugins.rest.client.RestBuilder
和使用restcuilder,但这也有同样的错误
Groovy:无法解析类
。我认为这些类不再存在于插件中。很抱歉,这段代码中出现了严重的问题。请尝试查看是否可以使用此类