当我使用 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") 时,测试就会通过。我不明白。
谢谢你的帮助!