我想完成以下事项:
I have two buttons. When first button is pressed,
it will fire onTouchEvent on second button, thus pressing second button.
Run Code Online (Sandbox Code Playgroud)
以下是触发事件的代码摘录:
int test1[] = new int[2];
button2.getLocationInWindow(test1); //--->getting coordinates of second button
Instrumentation m_Instrumentation = new Instrumentation();
//firing event
m_Instrumentation.sendPointerSync(MotionEvent.obtain(android.os.SystemClock.uptimeMillis(),android.os.SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,test1[0]+10, test1[1]+10, 0));
Run Code Online (Sandbox Code Playgroud)
注意:我使用genymotion模拟器.
错误日志:
07-08 12:47:38.743: E/InputEventReceiver(6849): Exception dispatching input event.
07-08 12:47:38.743: E/MessageQueue-JNI(6849): Exception in MessageQueue callback: handleReceiveCallback
07-08 12:47:38.743: E/MessageQueue-JNI(6849): java.lang.RuntimeException: This method can not be called from the main application thread
07-08 12:47:38.743: E/MessageQueue-JNI(6849): …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我启用了多索引.该应用程序在模拟器上运行良好.我正在使用robotium来测试应用程序.但是当我执行检测测试用例时,有时测试会通过,但大多数情况下它们在系统重启后也会失败.通过和失败之间没有代码更改.
默认gradle配置:
android {
defaultConfig {
applicationId "com.example.androidapp"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
testProguardFile "proguard-test.txt"
}
}
Run Code Online (Sandbox Code Playgroud)
还要为测试添加依赖项:
androidTestCompile fileTree(dir: 'libs', include:'robotium-solo-5.3.0.jar')
androidTestCompile ('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex' }
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中,我提到了应用程序标记:
<application
android:name="StartupActivity"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" ...../>
Run Code Online (Sandbox Code Playgroud)
我在StartupActivity中扩展了"android.support.multidex.MultiDexApplication".仪器测试用例下降的时间我得到以下错误:
INSTRUMENTATION_RESULT: shortMsg=java.lang.IllegalAccessError
INSTRUMENTATION_RESULT: longMsg=java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
INSTRUMENTATION_CODE: 0
Run Code Online (Sandbox Code Playgroud)
logcat中的错误消息是:
W/dalvikvm? Class resolved by unexpected DEX: Lcom/example/androidapp/StartupActivity;(0xa695df08):0x9910e000 ref [Landroid/support/multidex/MultiDexApplication;] Landroid/support/multidex/MultiDexApplication;(0xa695df08):0x99a2c000
W/dalvikvm? (Lcom/example/androidapp/StartupActivity; had used a different Landroid/support/multidex/MultiDexApplication; during pre-verification)
W/dalvikvm? Unable to …Run Code Online (Sandbox Code Playgroud) android gradle robotium android-instrumentation android-multidex
我设置了Espresso工具框架来运行我的Android Functional Automation测试。对于每个测试,我都想登录到该应用程序并在完成测试后删除该应用程序。
因此,我设置如下所示:
公共类FirstSampleTest扩展了BaseTest {
private final BaseTest baseTest;
Run Code Online (Sandbox Code Playgroud)
//私有最终ElementUtils elementUtils;
public FirstSampleTest() throws InterruptedException {
this.baseTest = new BaseTest();
}
@Before
public void initiate() throws InterruptedException {
//I have setup login method here to login to the app after it installs
}
@Rule
public ActivityTestRule<SplashScreenActivity> splashScreenActivityActivityTestRule = new ActivityTestRule(SplashScreenActivity.class);
@Test
public void testTheHomeScreen() throws InterruptedException {
//Some tests go here.
}
@After
public void teardown() throws InterruptedException {
//I want to uninstall the app or delete it from …Run Code Online (Sandbox Code Playgroud) 执行我们的一些仪器测试需要很长时间。因此,当我使用gradle connectedAndroidTest.
为什么我不用@Ignore注释这些测试?因为我想稍后使用这里adb shell描述的方式运行它们。
像这样:
运行除特定类中的测试之外的所有测试: adb shell am instrument -w -e notClass com.android.foo.FooTest com.android.foo/android.support.test.runner.AndroidJUnitRunner
如果我将这些测试标记为忽略并编译它们,则根本无法执行它们。
是否可以修改connectedAndroidTest或其他一些任务来达到我的需要?
我有一个包含多个库模块的Android项目.在应用程序模块中,我有一些测试应用程序主要功能的测试测试,我想在运行这些测试时记录代码覆盖率.
运行gradle任务"createDebugCoverageReport"时,会生成coverage报告(coverage.ec文件和html报告),但它显示只覆盖应用程序模块中的类,甚至还使用了库模块中的类.
我还尝试用勺子 - gradle-plugin使用Spoon记录测试覆盖率.在这种情况下,覆盖率报告仅覆盖应用程序模块中的类.
在运行检测测试时,有没有办法获得所有库模块的代码覆盖率?
我已经在每个模块中添加了以下内容:
debug {
testCoverageEnabled true
}
Run Code Online (Sandbox Code Playgroud) android code-coverage spoon android-instrumentation spoon-gradle-plugin
我在我的应用程序上启用了 Crashlytics,但我遇到了一个奇怪的崩溃,我在解释一些设备时遇到了问题。
崩溃日志包含android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126). 这是否意味着此崩溃发生在模拟器上,或者真实设备是否也有此检测代码?
Google 的Instrumentation 类文档建议如此,但我想确定:
用于实现应用程序检测代码的基类。在打开检测的情况下运行时,此类将在任何应用程序代码之前为您实例化,允许您监视系统与应用程序的所有交互。
这是崩溃日志中的更多上下文。
at android.app.Activity.performCreate(Activity.java:6955)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4978)
at android.app.ActivityThread.-wrap21(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1648)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Run Code Online (Sandbox Code Playgroud) 我正在使用 Espresso 进行自动化测试。
可以写入 Instrumentation 测试类的文件夹丢失
我尝试添加
android{
sourceSets{
main { java.srcDirs = ['src/main/java'] }
test { java.srcDirs = ['src/test/java'] }
androidTest { java.srcDirs = ['src/androidTest/java'] }
}
}
Run Code Online (Sandbox Code Playgroud)
在build.gradle里面,但没有用。
尝试使用此问题中提供的其他解决方案生成仍然不起作用
我们有一套 Android 仪器测试,我们通过 CL 运行这些测试。./gradlew app:connectedDebugAndroidTest如果测试失败,我们基本上必须等待所有测试完成,然后才能生成 HTML 报告。我们希望测试在第一个失败的测试中停止。是否有我们可以应用的 gradle 标志来实现这一目标?我在官方文档中没有找到任何内容。
我正在尝试为包含 WorkManager WorkRequests 的类编写 Android 检测测试。
很长一段时间,我都被困在我可以看到工人排队但他们从未被处决的地步。经过一段时间的反复试验,我意识到以下约束阻止了测试:
...
setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
...
Run Code Online (Sandbox Code Playgroud)
如果我删除该约束,工作项将按预期执行。
我的虚拟设备有网络连接,所以不确定为什么我的测试没有满足这个限制。
有没有人对如何解决这个问题有任何建议,因为我需要编写测试来涵盖满足和不满足此约束的情况。
我的工作要求非常简单,但它是:
val workRequest = OneTimeWorkRequestBuilder<T>()
.addTag(syncWork.getSyncType().name)
.setConstraints(Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build())
.build()
syncWorkRepository.save(syncWork.apply { id = workRequest.id.toString() })
workManager.enqueue(workRequest)
Run Code Online (Sandbox Code Playgroud)
我试过了:
val wifi = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
wifi.isWifiEnabled = true
Run Code Online (Sandbox Code Playgroud)
但这会引发安全异常:
SecurityException: WifiService: Neither user 10139 nor current process has android.permission.CHANGE_WIFI_STATE.
Run Code Online (Sandbox Code Playgroud)
我还在测试中添加了代码来检查网络状态:
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork: NetworkInfo? = cm.activeNetworkInfo
val isConnected: Boolean = activeNetwork?.isConnected == true
Run Code Online (Sandbox Code Playgroud)
并且 isConnected 为真但仍然不满足 WorkManager 约束,因此不执行工作。
还试过:
val testDriver = getTestDriver()
Run Code Online (Sandbox Code Playgroud)
和
testDriver?.setAllConstraintsMet(workInfo.id) …Run Code Online (Sandbox Code Playgroud) android android-testing android-instrumentation android-workmanager
我在Android Studio的androidTest目录中有一些Espresso测试。当我将光标移到绿色三角形(请参见下文)上以运行测试时,Studio会显示“运行测试”而不是“运行verifySomething”,然后继续以单元测试而不是Espresso测试的形式运行测试。在我从Studio 3.4升级到3.5之前,这种方法一直很好,尽管我无法确定这是根本原因。如果我去跑步| 编辑配置我可以看到Studio在左侧面板中添加了一个新条目“ Android JUnit”,而不是“ Android Instrumented Test”。如果我手动创建“ Android Instrumented Test”配置并手动添加“ verifySomething”方法,并且从Studio的顶层菜单栏配置下拉菜单中选择它,则可以将其作为Instrumented测试运行。
run-configuration android-studio android-espresso android-instrumentation