标签: android-testing

如何在连接到远程系统的设备上部署和执行应用程序?

我需要部署测试应用程序并在连接到同一网络中另一台计算机的设备上发出命令.

我通过http://developer.android.com/tools/help/adb.html#directingcommands阅读,但我无法找到答案.

我尝试过使用adb connect <remote machine IP>但是我收到了unable to connect错误.

有没有办法adb在连接到远程系统的设备上部署应用程序和执行命令?

android adb android-testing

6
推荐指数
1
解决办法
5349
查看次数

测试自定义View的onMeasure/onLayout/onDraw方法有什么好方法?

我只写了一个自定义的视图类,除其他事项外,允许开发者轻松地设置边界(如setBorderWidth,setBorderColor,setBorderWidthLeft,等).我通过覆盖onMeasure/来做到这一点onDraw,我想测试View正确绘制这些边框.

理想情况下,我想要一个比单元测试更高级别的东西:基本上我想强制执行,如果我设置边框,它们按预期绘制; 如果我不设置它们就不会被绘制; 如果我更改它们,则会绘制新边框并且不再显示旧边框.这让我知道我的观点正在高水平运作.

我考虑过的事情:

  1. 将视图与Robolectric隔离并使用模拟Canvas手动调用onDraw(尽管不测试失效)
  2. 制作一个Activity测试用例并以某种方式保存Activity的屏幕截图并以编程方式对其进行分析.

这些对我来说都不是很好,但我倾向于2).还有其他想法吗?

android android-custom-view android-layout android-testing

6
推荐指数
1
解决办法
927
查看次数

如何使用Espresso测试保存和恢复Android活动的状态?

有没有办法以编程方式测试活动的保存和恢复状态代码?我的意思是这样做:

如何测试为保存/恢复活动的生命周期而构建的代码?但是以自动化的方式.

我已经测试了activity.recreate()几乎我正在搜索的方法,但事实上它并没有重置我的活动字段,就像我正在杀死进程一样.因此即使我没有在我的onCreate方法中实现恢复功能,我的测试也可以通过(因为我的字段没有变化......).

我目前正在玩Espresso v2,我想知道这是否可能通过玩InstrumentationRegistry.getInstrumentation()

android android-testing android-espresso

6
推荐指数
1
解决办法
2224
查看次数

在Android中测试通知

我的Android应用程序有一个服务,根据应用程序的运行次数等参数向用户发送通知.通知在不同情况下的不同时间发送.我想测试在所有不同情况下是否在正确的时间发送通知.android是否提供了这种测试方式?

android android-testing android-uiautomator

6
推荐指数
2
解决办法
8236
查看次数

错误:任务执行失败':app:transformClassesWithMultidexlistForDebugAndroidTest'

我无法弄清楚为什么会出现这个错误.
这是完整的错误

 Error:Execution failed for task          
 ':app:transformClassesWithMultidexlistForDebugAndroidTest'.
 > java.io.IOException: The output jar is empty. Did you specify the proper       
  '-keep' options?
Run Code Online (Sandbox Code Playgroud)

我的gradle android项目没有"androidTest"所以我手动创建,测试文件夹在这里是文件夹结构的截图 在此输入图像描述

android junit4 android-testing

6
推荐指数
1
解决办法
3943
查看次数

测试无法匹配正确的意图组件

我在使用espresso意图来测试使用意图启动的活动时遇到了麻烦.执行流程以下列方式工作

  1. 在主活动中,单击一个按钮
  2. 该按钮执行AsyncTask以获取一些数据
  3. 在AsyncTask的onPostExecute中,我创建了一个intent add fetched data作为Intent Extra,然后启动一个显示所获取数据的新活动.

创建intent并启动新活动的代码如下所示:

@Override
protected void onPostExecute(String result) {
   Intent intent = new Intent(context, NewActivity.class);
   intent.putExtra(key, result);
   context.startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

这一切都在我运行应用程序时有效.至于使用espresso进行测试,测试代码如下所示:

...

@Rule
public IntentsTestRule<MainActivity> mIntentTestRule =
                           new IntentsTestRule<>(MainActivity.class, false);

@Test
public void testMainActivityAsyncTask() {
    // Find view with button
    onView(withText(R.string.button_text)).perform(click());

    // Ensure correct intent setup
    intended(allOf(
            hasComponent(NewActivity.class.getName()),
            hasExtraWithKey(key),
            toPackage("com.example.espresso")));

    // Ensure appropriate activity and view is launched
    onView(
            allOf(withId(R.id.expected_view),                                                   
            withText(isEmptyOrNullString())));

    // Let it go
    Intents.release();
}
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,测试失败并出现这些错误(为简洁起见):

...想要匹配1个意图.实际上匹配0意图.

匹配意图:[]

记录的意图:-Intent {cmp = com.example.doingstuff/com.example.espresso.NewActivity(has extras)}处理包:[[com.example.doingstuff]],extras:[Bundle …

android android-testing android-espresso

6
推荐指数
0
解决办法
635
查看次数

无法在Android JUnit 4检测测试中启动未绑定服务

我正在尝试使用测试支持库框架测试基本的未绑定服务:http: //developer.android.com/tools/testing-support-library/index.html

LocalService.java:

public class LocalService extends Service {
@Override
public IBinder onBind(Intent intent) {
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

LocalServiceTest.java:

@RunWith(AndroidJUnit4.class)
public class LocalServiceTest {
    @Rule
    public final ServiceTestRule mServiceRule = new ServiceTestRule();

    @Test
    public void testWithUnboundService() throws TimeoutException {
        Intent serviceIntent =
            new Intent(InstrumentationRegistry.getTargetContext(), LocalService.class);

        mServiceRule.startService(serviceIntent);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试运行测试时,我得到以下TimeoutException:

java.util.concurrent.TimeoutException: Waited for 5 SECONDS, but service was never connected
at android.support.test.rule.ServiceTestRule.waitOnLatch(ServiceTestRule.java:258)
at android.support.test.rule.ServiceTestRule.bindServiceAndWait(ServiceTestRule.java:207)
at android.support.test.rule.ServiceTestRule.startService(ServiceTestRule.java:137)
at com.example.android.testing.ServiceTestRuleSample.LocalServiceTest.testWithBoundService(LocalServiceTest.java:71)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at …
Run Code Online (Sandbox Code Playgroud)

android android-testing

6
推荐指数
2
解决办法
1455
查看次数

如何在单元测试中创建Bundle

我想测试一个处理Bundles的方法.但是,我无法在测试环境中创建(非null)Bundle对象.

给出以下代码:

Bundle bundle = new Bundle();
bundle.putString("key", "value");
boolean containsKey = bundle.containsKey("key");
Run Code Online (Sandbox Code Playgroud)

containsKeytrue如果代码在应用程序上下文中执行,但false如果在一个单元测试执行.

服务背景

测试环境

我无法弄清楚为什么会这样,以及如何为我的测试创建一个Bundle.

java junit android unit-testing android-testing

6
推荐指数
1
解决办法
4520
查看次数

Android Studio单元测试覆盖率显示为0%

我正在尝试检查单元测试的覆盖范围,所有的测试都通过了,但是当我通过右键单击测试文件来使用“使用覆盖率运行测试”来运行测试时,它完成后,一切恢复为0%吗?

看起来它应该只能阅读https://developer.android.com/studio/test/index.html,并且找不到任何说明为什么它将为所有内容返回0%的信息吗?

我缺少一些隐藏的设置来使它正常工作吗?

android-testing android-studio

6
推荐指数
1
解决办法
823
查看次数

使用 ANDROIDX_TEST_ORCHESTRATOR 时未发现测试

当我ANDROIDX_TEST_ORCHESTRATORtestOptions

testOptions {
    unitTests.includeAndroidResources = true
    animationsDisabled = true
    execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
Run Code Online (Sandbox Code Playgroud)

我运行仪器测试

./gradlew connectedStudioDebugAndroidTest --stacktrace
Run Code Online (Sandbox Code Playgroud)

我收到未找到测试的错误

com.android.builder.testing.ConnectedDevice > No tests found.[emu1(AVD) - 9] FAILED 
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
Run Code Online (Sandbox Code Playgroud)

当我ANDROIDX_TEST_ORCHESTRATORtestOptions

testOptions {
    unitTests.includeAndroidResources = true
    animationsDisabled = true
    // execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
Run Code Online (Sandbox Code Playgroud)

测试运行。

那么我怎样才能让测试运行ANDROIDX_TEST_ORCHESTRATOR呢?

编辑

我取得了一些进展:androidTests 在我的真实设备 …

android android-testing android-test-orchestrator

6
推荐指数
1
解决办法
841
查看次数