[英]Android unit test using instrumentation without Activity
I want to unit test some Android code in isolation from an Activity. 我想对一些Android代码进行独立于Activity的单元测试。 The code does some Bitmap processing.
该代码执行一些位图处理。 I already tried Robolectric and it appears the Bitmap it returns is some sort of facade and does not contain real pixel values so Robolectric is out of the question.
我已经尝试过Robolectric,并且它返回的位图似乎是一种外观,并且不包含实际像素值,因此Robolectric毫无疑问。 I want to isolate the code that does the processing from the rest of the system.
我想将进行处理的代码与系统的其余部分隔离。 I've tried
ActivityUnitTestCase
with an Activity I create in my test class, but the test fails at startActivity(intent, null, null);
我已经在我在测试类中创建的Activity上尝试过
ActivityUnitTestCase
,但是测试在startActivity(intent, null, null);
处失败startActivity(intent, null, null);
I'm assuming this is because the Activity is not part of the application (not listed in the manifest). 我假设这是因为Activity不是应用程序的一部分(清单中未列出)。
How can I run a piece of Android code, instrumented, without an Activity? 如何在没有活动的情况下运行经过检测的Android代码?
Figured it out. 弄清楚了。 Just use InstrumentationTestCase .
只需使用InstrumentationTestCase即可 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.