Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
从文件中读取json内容以使用Groovy脚本在SOUP UI中进行断言功能测试_Json_Testing_Groovy_Soapui_Assertion - Fatal编程技术网

从文件中读取json内容以使用Groovy脚本在SOUP UI中进行断言功能测试

从文件中读取json内容以使用Groovy脚本在SOUP UI中进行断言功能测试,json,testing,groovy,soapui,assertion,Json,Testing,Groovy,Soapui,Assertion,我正在使用它来测试web服务。为了自动化回归测试,我需要比较实际响应和预期输出。我将请求的实际响应解析为json对象。我在一个包含JSON内容的文本文件中获得了预期的输出 import groovy.json.JsonSlurper def response = messageExchange.response.responseContent def slurper = new JsonSlurper() def responseAsJsonObject = slurper.parseText

我正在使用它来测试web服务。为了自动化回归测试,我需要比较实际响应和预期输出。我将请求的实际响应解析为json对象。我在一个包含JSON内容的文本文件中获得了预期的输出

import groovy.json.JsonSlurper 
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def responseAsJsonObject = slurper.parseText response

//? Read json file content and parse it as an json object

assert fileContentAsJsonObject == responseAsJsonObject
我需要一种从文本文件中读取JSON内容并在Groovy中解析为JSON对象的方法

它起作用了!使用.text获取文件内容,并将文件内容解析到jsonSlurper,它将生成json对象


最好使用log.info在日志控制台上进行编写和调试。

JsonSlurper有一个解析文件的方法-使用它。谢谢,但我的问题是读取文件内容。
def fileContent = new File('D:\\test.json').text
def fileContentAsJsonObject = slurper.parseText fileContent