2014-03-05 84 views
0

我在Eclipse上爲我的應用程序創建了一個測試。我正在使用Robotium 5.0.1。我正在進行的測試是...啓動MainActivity.class>點擊menuitem(addperson)>這會自動將其添加到添加屏幕,並且編輯文本被填充並且按下「保存」,然後應用程序關閉;測試順利通過。如何在Android J Unit Test上循環測試?

我想要做的是運行多次測試,而不必重新運行測試,測試e.g應用程序添加100人。

這是我的測試類:

package com.androidbegin.databasetutorial.test; 

import com.androidbegin.databasetutorial.MainActivity; 
import com.robotium.solo.Solo; 
import com.androidbegin.databasetutorial.R; 

import android.test.ActivityInstrumentationTestCase2; 

public class InitialButtonTest extends 
    ActivityInstrumentationTestCase2<MainActivity> { 

private Solo solo; 
public InitialButtonTest() { 
    super(MainActivity.class); 

} 

@Override 
public void setUp() throws Exception { 
    //setUp() is run before a test case is started. 
    //This is where the solo object is created. 
    solo = new Solo(getInstrumentation(), getActivity()); 
} 

public void testAddRemove() throws Exception 
{ 
    solo.assertCurrentActivity("Check on first activity", MainActivity.class); 
    solo.clickOnActionBarItem(R.id.action_addperson); 
    solo.enterText(0, "id number"); 
    solo.enterText(1, "Name"); 
    solo.enterText(2, "Last Name"); 
    solo.enterText(3, "Address"); 
      solo.enterText(4, "Contact number"); 
      solo.enterText(5, "Code"); 
      solo.enterText(6, "Date"); 
    solo.clickOnMenuItem("Save Note"); 


} 
} 

能否請你幫我或引導我到一個循環的代碼,我可以實現這個代碼。

一些需求(雖然不是必需的): solo.enterText(0)< <如果可以添加一個最長7位數的隨機數。

任何幫助表示讚賞,在此先感謝!

回答

0

只是把它放在一個用於循環

public void testAddRemove() throws Exception 
{ 
    //it runs it 1000 times 
    addRemove(1000); 
} 

public void addRemove(int NUMBER_OF_TIMES) throws Exception 
{ 
for(int i=0; i<NUMBER_OF_TIMES; i++){ 
    solo.assertCurrentActivity("Check on first activity", MainActivity.class); 
    solo.clickOnActionBarItem(R.id.action_addperson); 
    solo.enterText(0, "id number"); 
    solo.enterText(1, "Name"); 
    solo.enterText(2, "Last Name"); 
    solo.enterText(3, "Address"); 
    solo.enterText(4, "Contact number"); 
    solo.enterText(5, "Code"); 
    solo.enterText(6, "Date"); 
    solo.clickOnMenuItem("Save Note"); 
} 
} 
+0

非常感謝!這似乎工作得很好。 – user3288677

相關問題