Junit+verify
上一篇 /
下一篇 2010-01-27 15:46:20
/ 个人分类:Selenium
想使用selenium RC做浏览器兼容性
测试,使用了eclipse+junit+ant作为测试平台.
在selenium中同时支持assert和verify两种断言模式.
如果使用assert,当遇到错误时,test case不会再继续被执行下去; 而如果使用verify,当遇到错误时,test case仍会继续运行,直到完成.
但在junit中创建测试代码时发现,junit不识别verify方法.
从网上搜索了N多次,都没有找到彻底的解决方法,后来咨询了单位一个做开发人员,这个问题总得有眉目了.
1. 首先不使用junit中的testcase类,而是使用
com.thoughtworks.selenium.SeleneseTestCase.import com.thoughtworks.selenium.*;
|
2.使用上述类就可以使用verify方法了,需要注意一点是:
This class adds a number of "verify" commands, which are like "assert" commands,
but they don't stop the test when they fail. Instead, verification errors are
all thrown at once during tearDown.
|
|
所以需要在teardown方法中,加后check verification的方法
public void tearDown() throws Exception { selenium.stop(); checkForVerificationErrors(); }
|
注意: checkForVerificationErrors();和 selenium.stop();的位置不要反了啊. 如果反了,当遇到verificationerror的情况,这个测试就不能关闭不了.
3.teardown()方法,使用junit默认定义teardown方法是如下
protected void tearDown() throws Exception { selenium.stop(); checkForVerificationErrors(); }
|
但junit总是报一个错误:
Cannot reduce the visibility of the inherited method from SeleneseTestCase
|
原因是:
因为接口定义的方法默认是public的,意思就是你没有任何访问修饰符的情况下,系统给接口的方法加上了一个public的访问修饰符。你Test实现了接口,并且实现了接口定义的方法,于是方法的访问修饰符只能比接口的访问修饰符高,但是类的默认访问修饰符是freidnly,降低了访问级别,所以会报错.
所以你Test实现的方法前面加上public就对了(具体不知道什么意思,咨询了一个开发人员后说的,哈哈,本人不懂代码哦.) |
后来将teardown()方法改成如下后,问题解决:
public void tearDown() throws Exception { selenium.stop(); checkForVerificationErrors(); }
|
收藏
举报
TAG: