我需要部署测试应用程序并在连接到同一网络中另一台计算机的设备上发出命令.
我通过http://developer.android.com/tools/help/adb.html#directingcommands阅读,但我无法找到答案.
我尝试过使用adb connect <remote machine IP>但是我收到了unable to connect错误.
有没有办法adb在连接到远程系统的设备上部署应用程序和执行命令?
我只写了一个自定义的视图类,除其他事项外,允许开发者轻松地设置边界(如setBorderWidth,setBorderColor,setBorderWidthLeft,等).我通过覆盖onMeasure/来做到这一点onDraw,我想测试View正确绘制这些边框.
理想情况下,我想要一个比单元测试更高级别的东西:基本上我想强制执行,如果我设置边框,它们按预期绘制; 如果我不设置它们就不会被绘制; 如果我更改它们,则会绘制新边框并且不再显示旧边框.这让我知道我的观点正在高水平运作.
我考虑过的事情:
这些对我来说都不是很好,但我倾向于2).还有其他想法吗?
有没有办法以编程方式测试活动的保存和恢复状态代码?我的意思是这样做:
如何测试为保存/恢复活动的生命周期而构建的代码?但是以自动化的方式.
我已经测试了activity.recreate()几乎我正在搜索的方法,但事实上它并没有重置我的活动字段,就像我正在杀死进程一样.因此即使我没有在我的onCreate方法中实现恢复功能,我的测试也可以通过(因为我的字段没有变化......).
我目前正在玩Espresso v2,我想知道这是否可能通过玩InstrumentationRegistry.getInstrumentation()?
我的Android应用程序有一个服务,根据应用程序的运行次数等参数向用户发送通知.通知在不同情况下的不同时间发送.我想测试在所有不同情况下是否在正确的时间发送通知.android是否提供了这种测试方式?
我无法弄清楚为什么会出现这个错误.
这是完整的错误
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)
我在使用espresso意图来测试使用意图启动的活动时遇到了麻烦.执行流程以下列方式工作
创建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 …
我正在尝试使用测试支持库框架测试基本的未绑定服务: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) 我想测试一个处理Bundles的方法.但是,我无法在测试环境中创建(非null)Bundle对象.
给出以下代码:
Bundle bundle = new Bundle();
bundle.putString("key", "value");
boolean containsKey = bundle.containsKey("key");
Run Code Online (Sandbox Code Playgroud)
containsKey是true如果代码在应用程序上下文中执行,但false如果在一个单元测试执行.
我无法弄清楚为什么会这样,以及如何为我的测试创建一个Bundle.
我正在尝试检查单元测试的覆盖范围,所有的测试都通过了,但是当我通过右键单击测试文件来使用“使用覆盖率运行测试”来运行测试时,它完成后,一切恢复为0%吗?
看起来它应该只能阅读https://developer.android.com/studio/test/index.html,并且找不到任何说明为什么它将为所有内容返回0%的信息吗?
我缺少一些隐藏的设置来使它正常工作吗?
当我ANDROIDX_TEST_ORCHESTRATOR在testOptions
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_ORCHESTRATOR在testOptions
testOptions {
unitTests.includeAndroidResources = true
animationsDisabled = true
// execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
Run Code Online (Sandbox Code Playgroud)
测试运行。
那么我怎样才能让测试运行ANDROIDX_TEST_ORCHESTRATOR呢?
编辑
我取得了一些进展:androidTests 在我的真实设备 …