我在我正在开发的应用程序上使用robotium测试框架,我在项目的第一阶段运行它,它没关系,但昨天我实施了更多的测试并且非常沮丧,因为它似乎就像测试项目一样,找不到我要测试的任何类。它发生在我更新SDK管理器的一些东西后,但我不确定它是否与我的问题有关。 无论如何,在logcat上有一个输出的例子:
05-06 16:30:27.541:E / dalvikvm(24080):找不到类' com.tuntzme.controller.activities.ActivityLogin',从方法com.tuntzme.test.activities中引用.ActivityLoginTest。
我的一个测试用例:
public class ActivityCadastroTest extends ActivityInstrumentationTestCase2<ActivityCadastro>{
private Solo solo;
public ActivityCadastroTest() {
super(ActivityCadastro.class);
}
public void TesteCadastroCamposVazios() {
solo.assertCurrentActivity("activity_errada", ActivityCadastro.class);
solo.clickOnActionBarItem(R.id.menu_item_pronto_cadastro);
solo.waitForText(MensagensException.CAMPO_EMAIL_VAZIO.toString());
solo.enterText(com.tuntzme.R.id.edit_text_email_cadastro, SharedStuff.Strings.EMAIL_TESTE_SUCESSFULL.value());
solo.waitForText(MensagensException.CAMPO_SENHA_VAZIO.toString());
}
public void TesteCadastroEmailInvalido() {
solo.assertCurrentActivity("activity_errada", ActivityCadastro.class);
solo.enterText(com.tuntzme.R.id.edit_text_email_cadastro, SharedStuff.Strings.EMAIL_TESTE_WRONG_FORMAT.value());
solo.enterText(com.tuntzme.R.id.edit_text_senha_cadastro, SharedStuff.Strings.SENHA_TESTE.value());
solo.enterText(com.tuntzme.R.id.edit_text_confirmar_senha_cadastro, SharedStuff.Strings.SENHA_TESTE.value());
solo.clickOnActionBarItem(R.id.menu_item_pronto_cadastro);
solo.waitForText(MensagensException.EMAIL_INVALIDO.toString());
}
public void TesteCadastroSenhaDivergente() {
solo.assertCurrentActivity("activity_errada", ActivityCadastro.class);
solo.enterText(com.tuntzme.R.id.edit_text_email_cadastro, SharedStuff.Strings.EMAIL_TESTE_SUCESSFULL.value());
solo.enterText(com.tuntzme.R.id.edit_text_senha_cadastro, SharedStuff.Strings.SENHA_TESTE.value());
solo.enterText(com.tuntzme.R.id.edit_text_confirmar_senha_cadastro, SharedStuff.Strings.SENHA_TESTE_DIVERGENTE.value());
solo.clickOnActionBarItem(R.id.menu_item_pronto_cadastro);
solo.waitForText(MensagensException.SENHAS_NAO_COINCIDEM.toString());
}
public void TesteCadastroSucesso() {
solo.assertCurrentActivity("activity_errada", ActivityCadastro.class);
solo.enterText(com.tuntzme.R.id.edit_text_email_cadastro, SharedStuff.Strings.EMAIL_TESTE_SUCESSFULL.value());
solo.enterText(com.tuntzme.R.id.edit_text_senha_cadastro, SharedStuff.Strings.SENHA_TESTE.value());
solo.enterText(com.tuntzme.R.id.edit_text_confirmar_senha_cadastro, SharedStuff.Strings.SENHA_TESTE.value());
solo.clickOnActionBarItem(R.id.menu_item_pronto_cadastro);
solo.waitForActivity(ActivityLogin.class);
}
}
我的测试项目清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tuntzme.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.tuntzme" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:targetPackage="com.tuntzme" android:name="android.test.InstrumentationTestRunner" />
最后是测试项目的订单和导出内容
希望有人可以帮助我,我真的很感激
答案 0 :(得分:1)
您可以尝试使用waitFor的其他方法:
solo.waitForText(); //如果在加载完成后出现某个文本
solo.waitForView(); //如果在加载屏幕完成后显示某个视图。
或者您可以使用
solo.assertCurrentActivity(“Expected MyActivity”,“MyActivity”);
使用像
这样的延迟的Thread.sleep(1500);
或
solo.sleep(1500);