2012-04-19 112 views
1

我正在爲我的Android應用程序編寫很多測試,這意味着大約有15個測試用例。我怎樣才能實現他們?我試圖在每個測試用例的同一個項目中創建幾個.java文件,但它只運行第一個。然後我做了一個Test,java並在裏面寫了幾個方法。如public void test1() throws Exception{...} public void test2() throws Exception{...}。但它也只是第一個測試案例。在運行配置中,我選擇了在選定項目中運行所有測試,運行時我可以在屏幕左側的JUnit窗口中看到它們,它成功運行第一個,顯示下一個正在處理,但它什麼都沒做(( ((使用Robotium的一個項目中的幾個測試/測試用例

回答

0

如果您正在使用robotium進行黑盒測試,這是烏爾班應該怎麼樣子:

public class TestAPK extends ActivityInstrumentationTestCase2 { 

private static final String TARGET_PACKAGE_ID="com.android.example";//your package name 
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.android.example.MainActivity"; //your main activity full class name 

private static Class launcherActivityClass; 
static{ 
    try{ 
     launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); 
    }catch(ClassNotFoundException e){ 
     throw new RuntimeException(e); 
    } 
} 

public TestAPK() throws ClassNotFoundException{ 
    super(TARGET_PACKAGE_ID,launcherActivityClass); 
} 
private Solo solo; 


protected void setUp() throws Exception{ 
    solo=new Solo(getInstrumentation(),getActivity()); 
} 
public void test1() throws Exception{...} 
public void test2() throws Exception{...} 
} 
2

記住在你的拆解(使用solo.finishOpenedActivities()),然後執行將不掛。

+0

非常感謝你!我可能應該開始閱讀文檔... – icecreamman 2012-07-09 21:31:14