问题描述
我正在使用 Flank/Firebase 测试实验室针对 Android API28 设备运行 JUnit4 测试,并且我从测试侦听器打印的所有日志消息都没有打印在设备的目录中。
我尝试了几件事:
尝试 1
println("===TEST")
尝试 2
import android.util.Log
Log.e("UnitTest","===TEST MESSAGE")
尝试 3
bundle = Bundle()
bundle.putString(Instrumentation.REPORT_KEY_IDENTIFIER,MyTestListener::class.java.name)
bundle.putString(InstrumentationResultPrinter.REPORT_KEY_NAME_CLASS,description.className)
bundle.putString(InstrumentationResultPrinter.REPORT_KEY_NAME_TEST,description.methodName)
bundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT,"=== TEST_FINISHED")
InstrumentationRegistry.getInstrumentation().sendStatus(InstrumentationResultPrinter.REPORT_VALUE_RESULT_OK,bundle)
这些方法似乎都没有将我的日志包含在 catlog
输出中...但我可以看到我的测试用例运行并通过了。有没有人有任何建议或知道我做错了什么?
当我使用断点在本地运行它时,我的代码肯定会被命中,并且消息正在打印到 Stdout。
谢谢!
解决方法
尝试 2 实际上应该是公认的答案:
import android.util.Log
Log.e("UnitTestClassName","===TEST MESSAGE")
我的具体问题是测试执行路径没有经过这些代码行。