robolectric

Resources$NotFoundException when running Roboelectric test

删除回忆录丶 提交于 2019-12-18 07:46:19
问题 I've just set up Roboelectric 3.2.2 with a new app and I have written my first simple test: @RunWith(RobolectricTestRunner.class) @Config(manifest="src/main/AndroidManifest.xml", packageName="my.pacakge.name.debug") public class MainActivityTest { @Test public void clickButton() { MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class); String text = ((TextView)mainActivity.findViewById(R.id.text_main)).getText().toString(); assertEquals("Should equal Hello World!", "Hello

Using multiple res folders with Robolectric

独自空忆成欢 提交于 2019-12-17 17:17:16
问题 My current Gradle configuration has multiple (Merged) res folders: sourceSets { androidTest { setRoot('src/test') } main { res.srcDirs = [ 'src/main/res/features/registration', 'src/main/res/features/login', 'src/main/res' ] } } But Robolectric allows me to configure a single directory using AndroidManifest: public class RobolectricGradleTestRunner extends RobolectricTestRunner { private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18; public RobolectricGradleTestRunner(Class<?>

Using multiple res folders with Robolectric

旧巷老猫 提交于 2019-12-17 17:13:42
问题 My current Gradle configuration has multiple (Merged) res folders: sourceSets { androidTest { setRoot('src/test') } main { res.srcDirs = [ 'src/main/res/features/registration', 'src/main/res/features/login', 'src/main/res' ] } } But Robolectric allows me to configure a single directory using AndroidManifest: public class RobolectricGradleTestRunner extends RobolectricTestRunner { private static final int MAX_SDK_SUPPORTED_BY_ROBOLECTRIC = 18; public RobolectricGradleTestRunner(Class<?>

Robolectric shadow not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:46:05
问题 I'm trying to create a test with Robolectric . My goal is to be able to replace the functionality of one class (that comes for example from a library and I can't modify the code) from a custom behaviour. I created this small test to simulate what I want to do: @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowMessenger.class}) public class TestShadow { @Test public void testMessenger() { OriginalMessenger messenger = new OriginalMessenger(); String message = messenger.getMessage(

Robolectric tests fail on shadowOf

不羁岁月 提交于 2019-12-14 03:12:49
问题 What might be the problem? My Robolectric tests ran fine a while ago, but now they all fail with the same error. The only change I can think of is changing to version 2.1.1. I'm running them with the RobolectricTestRunner and the run configuration points to the actual app directory. But every test fails because the app's application class is always null as preferences are being accessed: java.lang.NullPointerException: can't get a shadow for null at org.robolectric.bytecode.ShadowWrangler

SQLite existing database unit testing error using robolectric

爷,独闯天下 提交于 2019-12-13 20:27:05
问题 In my app, I have the SQLite database which I have put into assets folder. I successfully use it in my app, but now I want to test methods in database "provider" class which has several methods for CRUD operations. I tried to follow up this tutorial https://medium.com/@elye.project/android-sqlite-database-unit-testing-is-easy-a09994701162 but my test class fails with the exception android.database.sqlite.SQLiteException: Cannot open SQLite connection, base error code: 14 at org.robolectric

How to unit test to give coverage of exception branches

淺唱寂寞╮ 提交于 2019-12-13 17:46:25
问题 I write unit tests with JUnit4 and Mockito for my application and I want make full coverage. But I don't fully understand how cover exception branches. For example: try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } How I can invoke from tests exceptions? 回答1: While you may not easily be able to insert an exception into Thread.sleep in particular, because it's being called statically instead of against an injected instance, you can easily stub injected

Testing with Robolectric in Eclipse

岁酱吖の 提交于 2019-12-13 16:26:42
问题 I am trying to run a simple test with Robolectric in eclipse . I followed this tutorial, but got this error : java.lang.RuntimeException: java.io.FileNotFoundException: C:\Vishal\Development\workspace>\AndroidHelloWorldTester.\AndroidManifest.xml not found or not a file; it >should point to your project's AndroidManifest.xml Then as per Eugen's advice at here, I tried to extend the RobolectricTestRunner class as per instructed here but got this error :- (well I couldn't write the constructor

Error : java.lang.UnsatisfiedLinkError with roboelectric and realm

筅森魡賤 提交于 2019-12-13 12:25:18
问题 Hi I am using realm database for my application and using roboelectric unit testing framework for performing unit testing. I see realm is written in native c code, it has librealm-jni.so file for their functionality. I am getting UnsatisfiedLinkError error, read somewhere that robolectric does not support native libraries. I believe that there must be some way to resolve it. I tried accepted answer of this How to load .so when using Robolectric? but no luck. java.lang.UnsatisfiedLinkError:

can jmockit and robolectric coexist?

那年仲夏 提交于 2019-12-13 11:49:27
问题 I'm trying to implement a unit test using Robolectric to replace the stubbed methods in android.jar while also using jMockit to mock an Android class (Fragment, in my case). However, I can't seem to get it to work. If I annotate the test class with @RunWith(RobolectricTestRunner.class) , I get: java.lang.IllegalStateException: JMockit wasn't properly initialized; check that jmockit.jar precedes junit.jar in the classpath (if using JUnit; if not, check the documentation) If I use @RunWith