我正在为一个代码库编写自动测试(带有 ActivityInstrumentationTestCase2 的 Robotium),该代码库有很多包含静态变量的遗留代码,并希望确保我们在每个测试中开始的状态是相同的。
我们清除静态变量的方法是杀死整个进程然后重新启动它。这对应用程序本身很有效,但是在运行测试项目时,它会导致我们在控制台中收到“应用程序崩溃。_运行仪器”以及logcat中的以下行:
03-05 11:08:01.113: I/ActivityManager(70): Process com.____________ (pid 662) has died.
03-05 11:08:01.113: W/ActivityManager(70): Crash of app com.___________ running instrumentation
有谁知道是否有另一种方法来清除变量(不必一个一个地检查它们)或另一种方法来解决这个问题?
以下是 logcat 的更多内容:
03-05 11:07:59.553: D/____________(662): NEW STATE FROM SERVICE: STATE_SHUTTING_DOWN
03-05 11:07:59.613: I/TestRunner(662): finished: testLoginCorrectUserNameIncorrectPassword(com.____________.test.LoginScreenTest)
03-05 11:07:59.613: I/TestRunner(662): passed: testLoginCorrectUserNameIncorrectPassword(com.____________.test.LoginScreenTest)
03-05 11:07:59.613: I/TestRunner(662): started: testLoginIncorrectUserName(com.____________.test.LoginScreenTest)
03-05 11:07:59.643: I/ActivityManager(70): Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.____________/.____________ } from pid 662
03-05 11:08:00.183: D/dalvikvm(150): GC_CONCURRENT freed 185K, 51% free 2846K/5703K, external 957K/1462K, paused 3ms+102ms
03-05 11:08:01.075: D/____________(662): NEW STATE FROM SERVICE: STATE_TERMINATED
03-05 11:08:01.083: I/Process(662): Sending signal. PID: 662 SIG: 9
03-05 11:08:01.113: I/ActivityManager(70): Process com.____________ (pid 662) has died.
03-05 11:08:01.113: W/ActivityManager(70): Crash of app com.____________ running instrumentation ComponentInfo{com.____________.test/android.test.InstrumentationTestRunner}
03-05 11:08:01.123: D/AndroidRuntime(654): Shutting down VM
03-05 11:08:01.123: I/ActivityManager(70): Force stopping package com.____________ uid=10034
03-05 11:08:01.173: D/dalvikvm(654): GC_CONCURRENT freed 117K, 71% free 300K/1024K, external 0K/0K, paused 1ms+1ms
03-05 11:08:01.173: D/jdwp(654): Got wake-up signal, bailing out of select
03-05 11:08:01.173: D/dalvikvm(654): Debugger has detached; object registry had 1 entries
03-05 11:08:01.193: I/dalvikvm(654): JNI: AttachCurrentThread (from ???.???)
03-05 11:08:01.193: I/AndroidRuntime(654): NOTE: attach of thread 'Binder Thread #3' failed
03-05 11:08:01.252: W/InputManagerService(70): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40980df8
03-05 11:08:01.372: D/dalvikvm(219): GC_EXTERNAL_ALLOC freed 14K, 50% free 2868K/5639K, external 4235K/5259K, paused 44ms
感谢您的帮助,
托德