回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>尝试在robot框架中创建测试用例。在</p>
<p>我们有几个restapi返回Json作为结果。为了调用这种情况,我们在rest2.py中使用了以下代码</p>
<pre><code>def restJSON():
r = requests.get("http://httpbin.org/get")
# print "Code" , r.status_code
# print "Text " , r.text
return r.json()
</code></pre>
<p>我们将json存储在一个文件输出中。我们编写了robot测试用例来评估json比较,如下所示</p>
^{pr2}$
<p>但是,当我们运行pybot测试用例时,我们得到一个错误消息,说这两个json不相同。在</p>
<pre><code>--------------------------------
pybot testSuite.txt
--------------------------------
==============================================================================
testSuite
==============================================================================
Example that calls a python keyword | FAIL |
{u'origin': u'10.252.30.94, 69.241.25.16', u'headers': {u'Via': u'1.1 localhost (squid/3.1.14)', u'Accept-Encoding': u'gzip, deflate, compress', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.2.1 CPython/2.7.6 Linux/3.16.0-30-generic', u'Host': u'httpbin.org', u'Cache-Control': u'max-age=259200'}, u'args': {}, u'url': u'http://httpbin.org/get'} != {u'origin': u'10.252.30.94, 69.241.25.16', u'headers': {u'Via': u'1.1 localhost (squid/3.1.14)', u'Accept-Encoding': u'gzip, deflate, compress', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.2.1 CPython/2.7.6 Linux/3.16.0-30-generic', u'Host': u'httpbin.org', u'Cache-Control': u'max-age=259200'}, u'args': {}, u'url': u'http://httpbin.org/get'}
------------------------------------------------------------------------------
testSuite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
</code></pre>
<p>json文件是相同的。但它的失败测试案例表明两者并不相同。这是正确的比较方法吗,还是我们有其他方法可以在robot框架中进行比较。在</p>