Robotium でテストを実行するとき、アサーションを使用してページに特定のテキストがあることを確認しますが、失敗します。ただし、アサーションなしでテストを実行すると、テストは成功します。これはなぜでしょうか?
これが私のコードです:
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;
@SuppressWarnings("unchecked")
public class ODPRobotiumTest extends ActivityInstrumentationTestCase2 {
private static final String TARGET_PACKAGE_ID = "com.gravitymobile.app.hornbill";
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.vzw.odp.LaunchActivity";
private static Class<?>launcherActivityClass;
static{
try{
launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
@SuppressWarnings({ "unchecked", "deprecation" })
public ODPRobotiumTest() throws ClassNotFoundException{
super(TARGET_PACKAGE_ID, launcherActivityClass);
}
private Solo solo;
@Override
protected void setUp() throws Exception{
solo = new Solo(getInstrumentation(), getActivity());
}
@Smoke
public void testLine1(){
try {
assertTrue(solo.searchText("Easy to Find")) ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Smoke
public void testLine2(){
try{
solo.searchText("Hassle-Free");
}catch(Exception e){
e.printStackTrace();
}
}
@Smoke
public void testLine3(){
solo.searchText("Trust");
}
public void testLine4(){
solo.searchText("Verizon Curated Wallpaper");
}
public void testLine5(){
solo.searchText("Taco's");
}
@Override
public void tearDown() throws Exception{
try{
solo.finalize();
}catch(Throwable e){
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
testLine1 のテストは、失敗したテストです。しかし、前に言ったように、assertTrue を使用せず、solo.searchTest("Easy to find") だけを使用すると、テストはパスします。理解できない。
助けてくれてありがとう!