Roboitum中加入失败重跑机制
Robotium是个开源的android功能测试自动化框架,比较流行。我平时使用robotium maven spoon,这样的组合做androd自动化。做界面自动化,尤其是移动端,case经常失败,网络问题、等待机制不合理、手机问题等等。一个case失败后,再次运行可能又正常了,这种情况很多。其实我们在使用Robotium时,可以手动实现case失败后,重跑几次,如果几次都失败了,那么case才判定为失败。
方法
使用Robotium要继承Robotium的ActivityInstrumentationTestCase2
这个抽象类,并且要实现其中的setup
、tearDown
方法。其中还有一个方法runTest
就是控制执行我们的测试用例的,我们可以重载这个方法,实现case失败后重跑。代码如下:
@Override
protected void runTest() throws Throwable {
int retryTimes = 3;
while(retryTimes > 0)
{
try{
Log.d("Robotium", "super");
super.runTest();
break;
} catch (Throwable e)
{
if(retryTimes > 1) {
Log.d("Robo