简体   繁体   English

使用无活动的检测的Android单元测试

[英]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.

相关问题 使用检测和JUnit4测试重新创建Android Activity - Test recreating Android Activity using instrumentation and JUnit4 如何停止和重新启动 android 仪器测试中的活动? - How to stop and restart an activity in an android instrumentation test? 获取Android Instrumentation Test上的当前活动 - Get current Activity on Android Instrumentation Test 为什么没有在 Android 仪器测试(活动测试)中使用浓缩咖啡启动活动? - Why is activity not launching in Android Instrumentation test (Activity Test) with espresso? Android Studio 中的 Android Instrumentation 测试和单元测试的区别? - Difference between Android Instrumentation test and Unit test in Android Studio? Android-使用Instrumentation Framework进行单元测试 - Android - Unit testing using Instrumentation Framework 如何在android中的单元测试和仪器测试之间共享资源? - How to share resources between unit test and instrumentation test in android? Android Instrumentation Unit测试需要引用活动的适配器 - Android Instrumentation Unit testing an adapter that requires a reference to an activity 为具有动态特性的 Android 项目创建单元和仪器测试 - Create Unit and Instrumentation test for Android project with dynamic features 我应该使用Android Instrumentation编写单元测试吗? - Should I use Android Instrumentation to write unit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM