robolectric

Robolectric does not support API level 28

家住魔仙堡 提交于 2020-01-13 07:53:02
问题 Although this question has been answered for previous versions in other threads, none of the answers seems to work for me with api 28 right now so.. All Robolectric tests worked fine when on api 27. Now when my app api target is 28 they all fail. I have @Config(constants = BuildConfig::class, sdk = [Build.VERSION_CODES.P]) on my test class. Diving into Robolectrics internal SdkConfig.java it looks like they add support for api 28: addSdk(Build.VERSION_CODES.P, "P", "4651975", "P"); But when

PowerMock + Robolectric + Dagger2. Part I

荒凉一梦 提交于 2020-01-13 05:14:53
问题 This question was created from first part of PowerMock + Robolectric + Dagger2 So i'm a little bit again. Sorry. I test custom view class which contain: android ui elements some logic static methods callings dagger2 dependencies So i use next tools for testing Robolectric for UI elements mocking unit tests for logic testing PowerMock for static methods mocking Robolectric + PowerMock integration problem is known and solution is known - https://github.com/robolectric/robolectric/wiki/Using

Android http testing with Robolectric

安稳与你 提交于 2020-01-12 04:50:07
问题 I have an Android app where the main part of the app is the APIcalls.java class where I make http requests to get data from server an display the data in the app. I wanted to create unit test for this Java class since it's the most part of the app. Here is the method for getting the data from server: StringBuilder sb = new StringBuilder(); try { httpclient = new DefaultHttpClient(); Httpget httpget = new HttpGet(url); HttpEntity entity = null; try { HttpResponse response = httpclient.execute

一文全面了解Android单元测试

浪尽此生 提交于 2020-01-08 10:28:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 前言 成为一名优秀的Android开发,需要一份完备的 知识体系 ,在这里,让我们一起成长为自己所想的那样~。 ==》完整项目单元测试学习案例 众所周知,一个好的项目需要不断地打造,而一些有效的测试则是加速这一过程的利器。本篇博文将带你了解并逐步深入Android单元测试。 什么是单元测试? 单元测试就是针对类中的某一个方法进行验证是否正确的过程,单元就是指 独立的粒子 ,在Android和Java中大都是指方法。 为什么要进行单元测试? 使用单元测试可以提高开发效率,当项目随着迭代越来越大时,每一次编译、运行、打包、调试需要耗费的时间会随之上升,因此,使用单元测试可以不需这一步骤就可以对单个方法进行功能或逻辑测试。 同时,为了能测试每一个细分功能模块,需要将其相关代码抽成相应的方法封装起来,这也在一定程度上改善了代码的设计。因为是单个方法的测试,所以能更快地定位到bug。 单元测试case需要对这段业务逻辑进行验证。在验证的过程中,开发人员可以 深度了解业务流程 ,同时新人来了看一下项目单元测试就知道 哪个逻辑跑了多少函数,需要注意哪些边界 ——是的,单元测试做的好和文档一样 具备业务指导能力。 Android测试的分类 Android测试主要分为三个方面: 单元测试(Junit4、Mockito

Robolectric junit test - missing internet permission

╄→гoц情女王★ 提交于 2020-01-03 20:03:01
问题 I am developing some JUnit test for ma app. I need to use Robolectric + Roboguice libraries. What I am trying to do now is only simple test which checks if activity is not null. Here is my code: @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP, application = TestBoomerangManagerApplication.class, manifest = "src/main/AndroidManifest.xml") public class SimpleTest { private DirectInviteEmployeesActivity activity; @Before

asyncTask test doesn't execute

故事扮演 提交于 2020-01-03 08:57:09
问题 I'm using robolectric to test my AsyncTask class. In the test it does what I expect when the task is run like so: asyncTask.execute() But when I do asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) it doesn't (in both instances I run Robolectric.runUiThreadTasksIncludingDelayedTasks() Anyone have any idea why calling executeOnExecutor doesn't trigger Robolectric to run but execute works fine? 回答1: The Robolectric framework cannot work out of the box with the default executors (i.e.

Using the Android KeyStore in Robolectric tests

家住魔仙堡 提交于 2020-01-03 08:48:10
问题 I'm attempting to write a few testcases that work against the Android Keystore. However, when I write the following test case: @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21) public class FancyPantsUnitTest { @Test public void buildKey() { keyPairGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore"); keyPairGenerator.initialize(4096); final KeyPair keyPair = keyPairGenerator.generateKeyPair(); } } This fails with the following

Using the Android KeyStore in Robolectric tests

人走茶凉 提交于 2020-01-03 08:48:05
问题 I'm attempting to write a few testcases that work against the Android Keystore. However, when I write the following test case: @RunWith(RobolectricGradleTestRunner.class) @Config(constants = BuildConfig.class, sdk = 21) public class FancyPantsUnitTest { @Test public void buildKey() { keyPairGenerator = KeyPairGenerator.getInstance("RSA", "AndroidKeyStore"); keyPairGenerator.initialize(4096); final KeyPair keyPair = keyPairGenerator.generateKeyPair(); } } This fails with the following

Robolectric, Problems with clicking list items

隐身守侯 提交于 2020-01-02 01:55:15
问题 I have been struggling with this problem a bit, and I think I am not getting something fundamental about Robolectric. Usually some google searches can help me get to the bottom of this type of problem, but between that and looking at the sample code I am not finding anything of use. I am trying to emulate a click on a list view item and check that an activity is launched after the click. I keep getting back that the current activity I am testing is the resulting activity. I tried removing all

How to unit test android audio recording app using robolectric

ⅰ亾dé卋堺 提交于 2020-01-01 09:42:04
问题 I just want to know whether it is possible to unit test android audio recorder app using the Robolectric framework. As far as I know, Robolectric does not use the emulator or real device for testing. But in audio recording app, I need to test whether audio is getting recorded? Does it get stored at the specified location on SD card? Does it get played using the media player? and many other scenarios. I have looked into many Robolectric tutorials but they do not answer my question. I had also