在Android设备上运行测试sdk 26会导致它们失败,因为新的自动填充功能会在espresso尝试点击它们时隐藏字段.
我在firebase测试实验室运行我的测试,所以我不能在我的测试设备上手动禁用它们.
一些图片:
Espresso无法点击现在的密码字段,因为自动填充对话框隐藏了我的字段和fail.
AutofillManager#disableAutofillServices()仅使用禁用#2.对话但#3.还在那里.
如何在测试设备上禁用自动填充?
testing android android-testing android-espresso android-autofill-manager
我想要测试onHandleIntent()的方法IntentService使用Robolectric.
我正在启动服务:
Activity activity = new Activity();
Intent intent = new Intent(activity, MyService.class);
activity.startService(intent);
ShadowActivity shadowActivity = Robolectric.shadowOf(activity);
Intent startedIntent = shadowActivity.getNextStartedService();
assertNotNull(startedIntent);
Run Code Online (Sandbox Code Playgroud)
似乎startedIntent不是null,但onHandleIntent()似乎没有被调用.
我该怎么测试呢?
我正在开发一个独立的库项目,需要持久化一个简单的模型.这是我的SugarRecord样子:
/**
* Keeping track of previously received messages by ID
*/
public class MessageRequestIdModel extends SugarRecord {
protected String messageRequestId;
public MessageRequestIdModel() {
}
public MessageRequestIdModel(String messageRequestId) {
this.messageRequestId = messageRequestId;
}
public String getMessageRequestId() {
return this.messageRequestId;
}
public static boolean exists(String id) {
return MessageRequestIdModel.find(
MessageRequestIdModel.class,
"messageRequestId = ?",
id
).size() != 0;
}
}
Run Code Online (Sandbox Code Playgroud)
在存储库类中,我试图通过调用此方法来持久化它:
@Override
public void save(MessageRequestId messageRequestId) {
new MessageRequestIdModel(messageRequestId.getId()).save();
}
Run Code Online (Sandbox Code Playgroud)
我现在尝试通过使用android.test.InstrumentationTestCase我传递Context给Sugar 的地方来测试它,如下所示:
SugarContext.init(getInstrumentation().getContext());
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,这会导致此错误:(截断以使此问题简洁易读)
android.database.sqlite.SQLiteException: no …Run Code Online (Sandbox Code Playgroud) @Test
public void test3_PaySuccessful(){
init();
ViewInteraction amountEditText = onView(
allOf(withId(R.id.et_amount), isDisplayed()));
amountEditText.perform(replaceText("SGD 0.010"), closeSoftKeyboard());
//, withText("Proceed")
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.btn_confirm), isDisplayed()));
appCompatButton.perform(click());
//, withText("Pay")
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.btn_confirm), isDisplayed()));
appCompatButton2.perform(click());
//dialog
ViewInteraction appCompatButton3 = onView(
allOf(withId(R.id.confirm_button), withText("Confirm"), isDisplayed()));
appCompatButton3.perform(click());
//have to disable animation in order to pass this.
intended(CoreMatchers.allOf(hasComponent(PaymentSelectionActivity2.class.getName())));
}
Run Code Online (Sandbox Code Playgroud)
我在使用涉及动画的视图进行Espresso测试时遇到了一个问题,我知道Espresso无法处理动画,所以我在下面做了. - 禁用我的测试设备窗口动画,过渡动画和动画设计持续时间缩放都设置为OFF(这不起作用) - 然后我尝试在我的代码中添加一个标志,例如.espresso_testing = true.如果为true,我的代码将跳过调用所有startAnimation()函数调用.--->这是有效的.但是,在编写espresso测试用例时,我无法更改应用程序中的代码.包括上面的测试用例.
有没有其他方法可以做到这一点?提前致谢.
我遇到了一个问题,当我尝试运行 Android Instrument 测试时,android studio 将开始构建,一切都很好,直到它卡在这一行
"> 任务:app:connectedDebugAndroidTest"
并运行接下来的 2 小时,不再进行实际测试。我所看到的是,测试应用程序已成功内置到我的设备中,但无法打开和运行。
奇怪的是,我之前构建成功过一次,但是当我再次尝试构建时,就再也没有成功过。即使我没有更改代码。
这是我尝试过的事情
但还是无法构建!
这是我的仪器测试课屏幕截图
运行过程截图
以前有人遇到过这个问题吗?
android android-testing android-studio android-espresso instrumented-test
你如何测试Android中的 GPS应用程序?我们可以使用Android模拟器进行测试吗?
我想在LinearLayout的textview中显示文本字符串.能浓缩咖啡吗?如果没有,还有其他方法可以做到这一点,还是我可以在espresso测试用例中使用android api?我使用的是API 17 18或更新的espresso 1.1(它应该是最新的.).我对此毫无头绪.谢谢.
Google为Android编写测试提供了新的类,尤其是使用jUnit 4:https://developer.android.com/tools/testing-support-library/index.html
我想知道是否可以使用来自jUnit的AndroidJUnit4运行器以及参数化运行器?
在我的测试案例中,我必须记录1小时,在机器人solo.sleep(600000)完成了我的工作,但在浓缩咖啡中,我对IdlingResource概念感到困惑.我必须开始录音并等待一段时间(取决于测试类型)15分钟,60分钟等.
机器人中的等效代码
solo.clickOnView(solo.getView("start_record"));
solo.sleep(duration * 60 * 1000);
solo.clickOnView(solo.getView("stop_record"));
Run Code Online (Sandbox Code Playgroud)
我尝试在浓缩咖啡中使用它
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AaEspressoTest {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.absd.rec.RecorderActivity";
private static Class<?> launcherActivityClass;
private Solo solo;
private static CoreRecordingTest skyroTestRunner;
private static Class<? extends Activity> activityClass;
static {
try {
activityClass = (Class<? extends Activity>) Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
@Rule
public final ActivityTestRule<?> activityRule
= new ActivityTestRule<>(activityClass);
private IntentServiceIdlingResource idlingResource;
@Before
public void registerIntentServiceIdlingResource() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); …Run Code Online (Sandbox Code Playgroud) 我曾经使用Robotium编写Android测试并使用Emma检索覆盖率.
最近我改为使用Espresso测试,我很难找到仪器测试的覆盖范围.我只能检索使用Robolectric的单元测试的覆盖范围.我目前正在使用gradle和Jacoco来做到这一点.我找到的帮助我达到这一点的最佳教程是:https://blog.gouline.net/2015/06/23/code-coverage-on-android-with-jacoco/
是否可以检索使用Android检测的Espresso测试的覆盖范围?
android code-coverage android-testing android-espresso gradle-android-test-plugi
android-testing ×10
android ×9
testing ×2
animation ×1
gps ×1
junit ×1
junit4 ×1
robolectric ×1
sqlite ×1
sugarorm ×1