grails“test-app”功能性geb + spock测试失败,但“测试应用功能”是成功的 [英] grails "test-app" fails for functional geb+spock test but "test-app -functional" is successfull

查看:115
本文介绍了grails“test-app”功能性geb + spock测试失败,但“测试应用功能”是成功的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用GEB + Spock的Grails中进行功能测试时遇到了一些问题。如果我运行test-app,它总是失败,但是如果我在test-app之前运行test-app -integration,它会起作用!



以下测试序列说明了我的问题:

运行#1

 的grails>清理
grails> test-app -functional
...
测试已通过

运行#2

  grails>清理
grails>测试应用程序
...
测试失败

运行#3



  grails>清理
grails> test-app -functional
...
测试通过
grails> test-app
...
测试通过

测试失败抛出geb.waiting.WaitTimeoutException:条件在10.0秒内未通过。值得注意的是,失败的测试用例正在等待数据库查询的结果。



所以我的问题是, em>功能测试通过test-app -integration与test-app运行? 认为是测试应用程序正在运行所有测试阶段(单元,集成,功能)。



奇怪的是它不管怎样,但只有当我首先运行test-app -integration时:/ b / b>

使用以下设置:




  • grails 2.0.1

  • geb 0.7.0

  • spock 0.6


  • htmlunit-driver 2.0rc3(我尝试使用2.20.0,但给了我更多问题)




真的希望有人能帮助我解决这个问题。 Geb + spock似乎是一个很好的解决方案, 当它工作...



问候
Tobbe

$ b

解决方案

我设法解决这个问题,如果感兴趣的话可以在这里写解决方案给其他人。这个解决方案是通过使用geb报告功能(伟大的工具!)找到的。



问题是,在应用程序中使用Grails ZKUI的im很多,功能测试正在使用zkui在不同的测试场景中生成不同的html代码(这真的很奇怪)。



例如作曲家的zk按钮:

 < z:button id =simpleSearchButtonclass =simpleSearchButton/> 

运行test-app -integration时,它生成以下内容:

 < span id =cECQ4class =simpleSearchButton z-button>< table id =cECQ4-boxstyle =cellpadding =0cellspacing =0border =0>< tbody>< tr>< td class =z-button-tl/>< td class =z-button-tm < td class =z-button-tr/>< / tr>< tr>< td class =z-button-cl>< button type =button id =cECQ4-btnclass =z-button/>< / td>< td class =z-button-cm>< img src =/ certservice-admin / images / search .png; jsessionid = 2ADDD6FA5F1D011A96E447435514BDA2align =absmiddle/>< / td>< td class =z-button-cr>< div>< / div>< / td>< / tr>< tr>< td class =z-button-bl/> td class =z-button-bm/>< td class = < / TR>< / tbody的>< /表>< /跨度> 

但是当运行test-app时,它会生成以下内容:

 < button type =buttonid =l9AP4class =simpleSearchButton z-button-os>< img src =/ certservice- admin / images / search.png; jsessionid = 835A2B8A3FE0C54341BB4F109A0CCC62align =absmiddle/>< / button> 

在我的Page对象中,我将按钮定义为:

  simpleSearchButton(必填:false){$(span.simpleSearchButton)} 

其中test-app失败,但没有test-app -integration。对于难/奇怪问题的简单解决方案是:

pre $ simpleSearchButton(required:false){$(。simpleSearchButton)}



干杯
/ Tobbe

I have some problems regarding functional testing in Grails using GEB+Spock. If i run "test-app" it always fails, but if i run "test-app -integration" before "test-app" it works!

The following test-sequence illustrates my problem:

Run #1

grails> clean
grails> test-app -functional
...
Tests PASSED

Run #2

grails> clean
grails> test-app
...
Tests FAILED

Run #3

grails> clean
grails> test-app -functional
...
Test PASSED
grails> test-app
...
Test PASSED

The tests that are failing are throwing "geb.waiting.WaitTimeoutException: condition did not pass in 10.0 seconds". It is worth noting that the test cases that are failing are waiting for results from a database query.

So my question is what exactly is the difference then the functional tests are run through "test-app -integration" versus "test-app"?

The only difference from what i thought was that "test-app" is running all test phases (unit, integration, functional).

And the weird thing is that it do works somehow, but only if i run "test-app -integration" first :/

Im using the following setup:

  • grails 2.0.1
  • geb 0.7.0
  • spock 0.6
  • htmlunit-driver 2.0rc3 (ive tried with 2.20.0 but gave me even more problems)

Really hoping that someone can help me on this. Geb+spock seems like a nice solution, when it works...

Regards Tobbe

解决方案

I managed to solve this problem and writing the solution here for others if interested. THe solution was found by using geb report function (great tool!)

The Problem was that im using grails ZKUI alot in the application that the functional tests are working against and zkui generated different html-code in the different test scenarios (yep this is really odd).

For example a zk button i the composer:

<z:button id="simpleSearchButton" class="simpleSearchButton"/>

When running "test-app -integration" it generated the following:

<span id="cECQ4" class="simpleSearchButton z-button"><table id="cECQ4-box" style=""     cellpadding="0" cellspacing="0" border="0"><tbody><tr><td class="z-button-tl"/><td class="z-button-tm"/><td class="z-button-tr"/></tr><tr><td class="z-button-cl"><button type="button" id="cECQ4-btn" class="z-button"/></td><td class="z-button-cm"><img src="/certservice-admin/images/search.png;jsessionid=2ADDD6FA5F1D011A96E447435514BDA2" align="absmiddle"/></td><td class="z-button-cr"><div></div></td></tr><tr><td class="z-button-bl"/>td class="z-button-bm"/><td class="z-button-br"/></tr></tbody></table></span>

But when running "test-app" it generated the following:

<button type="button" id="l9AP4" class="simpleSearchButton z-button-os"><img src="/certservice-admin/images/search.png;jsessionid=835A2B8A3FE0C54341BB4F109A0CCC62" align="absmiddle"/></button>

In my Page object i defined the button as:

simpleSearchButton(required: false) { $("span.simpleSearchButton") }

Which failed with "test-app" but not with "test-app -integration". The simple solution to the hard/wierd problem was:

simpleSearchButton(required: false) { $(".simpleSearchButton") }

:)

Cheers /Tobbe

这篇关于grails“test-app”功能性geb + spock测试失败,但“测试应用功能”是成功的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆