robolectric

Robolectric with Gradle: Resources not found

左心房为你撑大大i 提交于 2019-11-28 02:57:43
I'm trying to run my Robolectric tests together with the new Gradle Android build system, but I'm stuck at accessing the resources of my main project. I split the build into two separate projects to avoid conflicts between the java and the android gradle plugins, so the directory structure looks roughly like this: . ├── build.gradle ├── settings.gradle ├── mainproject │ ├── build │ │ ├── classes │ │ │ └── debug │ ├── build.gradle │ └── src │ └── main │ ├── AndroidManifest.xml │ └── ... └── test ├── build.gradle └── src └── test └── java └── ... └── test ├── MainActivityTest.java ├── Runner

Using multiple res folders with Robolectric

萝らか妹 提交于 2019-11-28 02:17:21
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<?> testClass) throws InitializationError { super(testClass); } @Override protected AndroidManifest

Robolectric 2.1 and Eclipse

冷暖自知 提交于 2019-11-28 01:01:34
问题 Robolectric seems to be a very interessting alternative android application testing, but I can't properly integrate it with my Eclipse enviroment. Using the latest robolectric version 2.1 and android sdk 8, I follow the Eclipse setup steps described on the robolectric website but with no luck. When I run my newly created run configuration, the test is stopped the following error. I don't know exactly why my pakpak .R class cant be found and what is the ro.build.date.utc? a symptom or the

Robolectric shadow not working

有些话、适合烂在心里 提交于 2019-11-28 00:58:55
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(); Assert.assertEquals("Shadow messenger", message); } public static class OriginalMessenger { public

Gradle + Robolectric: Where do I put the file org.robolectric.Config.properties?

别等时光非礼了梦想. 提交于 2019-11-27 22:04:11
问题 I'm trying to setup a test using Robolectric to click on a menu button in this repository. Basic Robolectric tests will run, but I'm not able to run any project-specific test using resources because it says it can't find my AndroidManifest.xml. After running ../gradlew clean check , here's the standard output from the Robolectric html file: WARNING: No manifest file found at ./AndroidManifest.xml.Falling back to the Android OS resources only. To remove this warning, annotate your test class

Jvm options in android when run gradlew test

孤者浪人 提交于 2019-11-27 21:16:35
问题 I have a project that using Robolectric for unit test purpose. This project uses Robolectric 3.0 and need to add -ea and -noverify options in Virtual Machine options. In Android Studio, I created new JUnit configuration in Run > Edit Configurations... and then set VM Options to -ea -noverify . With this way I success to run my unit test. This is image about my configure, view Here However, for continuous deployment, I need run unit test with command line. So I use ./gradlew test to run unit

Testing SQLite database in Robolectric

混江龙づ霸主 提交于 2019-11-27 20:58:42
问题 I'm trying to test a simple SQLite database using Robolectric in my Android application. I'm putting in some values, but when reading them back 0 rows are returned. I'm using the SQLiteOpenHelper class to access the database. // RequestCache extends SQLiteOpenHelper RequestCache cache = new RequestCache(activity); SQLiteDatabase db = cache.getWritableDatabase(); // Write to DB ContentValues values = new ContentValues(); values.put(REQUEST_TIMESTAMP, TEST_TIME); values.put(REQUEST_URL, TEST

How to run unit tests with Android Studio

二次信任 提交于 2019-11-27 19:02:43
I'm using Jake's Android unit tests plugin for gradle: https://github.com/JakeWharton/gradle-android-test-plugin My build.gradle looks like this: dependencies { // analytics compile('com.crittercism:crittercism-android:3.0.11') // retrofit compile('com.squareup.retrofit:retrofit:1.2.2') compile('com.squareup.okhttp:okhttp:1.2.1') // dagger compile('com.squareup.dagger:dagger:1.1.0') compile('com.squareup.dagger:dagger-compiler:1.1.0') // compatibility compile('android.compatibility:android-support:v4-r13') compile('com.actionbarsherlock:actionbarsherlock:4.4.0@aar') // Picasso compile('com

Robolectric: Resources$NotFoundException: String resource ID with Android Gradle Plugin 3

旧街凉风 提交于 2019-11-27 17:05:53
问题 Android Studio 3.0 Beta2 classpath 'com.android.tools.build:gradle:3.0.0-beta3' testCompile 'org.robolectric:robolectric:3.4.2' Test class that I am using that fails to run: @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricTestRunner.class) public class RecipeAdapterTest { private MainActivity activity; @Before public void setup() { activity = Robolectric.setupActivity(MainActivity.class); /* Also tried this same Error activity = Robolectric

How can I test fragments with Robolectric?

空扰寡人 提交于 2019-11-27 11:05:44
I know there is a Robolectric.shadowOf(Fragment) method and a ShadowFragment class, thought they aren't listed on the docs, but I can't make it work. myFragment = new MyFragment(); myFragment.onCreateView(LayoutInflater.from(activity), (ViewGroup) activity.findViewById(R.id.container), null); myFragment.onAttach(activity); myFragment.onActivityCreated(null); I'm working with API level 13 (Honeycomb). Thanks. colabug Edit #4 & #5 : In Robolectric 3.* , they split up the fragment starting functions. For support fragments, you will need to add a dependency to your build.gradle : testCompile "org