-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add support for Robolectric on Max OS X #1867
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
994feec
ab599a4
735ccb4
5380abd
066ae5e
d4dc02a
c4602cb
39b455c
5c6eaf5
6e659f4
b1ed203
669266c
64ed2b2
393ee11
b3b2995
54b74da
20e5b97
5878f0e
368247e
b020122
7c41b8f
d4764cb
7a59bfe
e6f19d4
c3242be
2f5c9f1
72eb8d9
f93e81b
fbf2a52
ffc8ef9
21a2f5b
4520c9a
9c859f5
0189e69
69ccf00
911a59c
cf008ad
4d2c8d7
ec65ddd
a5454ff
defd84e
a87602f
2aae168
ba4dd13
ae2b224
106a762
ce98b1d
d6dbd11
4d4a405
71b8a89
b13105b
3036445
337a6e1
a1e68df
fd7cec4
72a6ef2
d8f9bba
26f0dc4
057f505
99aca03
af581ab
5feff19
cb47ccd
ea13014
cb3028b
74d57fe
18629ac
88df7bd
647adee
3f0a3b0
d8c0fca
bc7e919
442af20
94e8927
749d6c2
60d2712
31ee939
f9911ba
2f94973
31163df
23c6d60
4294d7d
8a79e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ realm_version_check.timestamp | |
|
|
||
| # Build artifacts | ||
| *.so | ||
| *.dylib | ||
| *.d | ||
| *.o | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,20 @@ task installRealmJava(type:Task) { | |
| description = 'Install the Realm library and Gradle plugin into mavenLocal()' | ||
| } | ||
|
|
||
| task installRobolectric(type:GradleBuild) { | ||
| description = 'Install the Robolectric library into example' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provide a group for all the new tasks
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added groups.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When invoking
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zaki50 What version of realm-core do you use? I guess you are not using v0.95.7, or you installed another version on your
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zaki50 Since I modified
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dalinaum right. How do I update that? /usr/local/include/realm/version.hpp
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can uninstall the old version using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zaki50 If you set
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dalinaum thx! |
||
| group = 'Install' | ||
| buildFile = file('realm/build.gradle') | ||
| tasks = ['installRobolectric'] | ||
| } | ||
|
|
||
| task assembleRobolectric(type:GradleBuild) { | ||
| description = 'Assemble the Robolectric support' | ||
| group = 'Build' | ||
| buildFile = file('realm/build.gradle') | ||
| tasks = ['assembleRobolectric'] | ||
| } | ||
|
|
||
| task assembleExamples(type:GradleBuild) { | ||
| dependsOn installGradlePlugin | ||
| dependsOn installRealm | ||
|
|
@@ -174,6 +188,16 @@ task distributionPackage(type:Zip) { | |
| } | ||
| } | ||
|
|
||
| task createRobolectricDistributionPackages(type:Zip) { | ||
| description = 'Create the Robolectric distribution package' | ||
| dependsOn assembleRobolectric | ||
|
|
||
| archiveName = "realm-robolectric-darwin-${currentVersion}.zip" | ||
| destinationDir = file("${buildDir}/outputs/distribution") | ||
|
|
||
| from('realm/realm-jni/build/librealm-jni-darwin.dylib') | ||
| } | ||
|
|
||
| task cleanRealm(type:GradleBuild) { | ||
| description = 'Clean the Realm project' | ||
| group = 'Clean' | ||
|
|
@@ -220,6 +244,12 @@ task uploadDistributionPackage(type: Exec) { | |
| commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-java-${currentVersion}.zip", 's3://static.realm.io/downloads/java/' | ||
| } | ||
|
|
||
| task uploadRobolectricDistributionPackage(type: Exec) { | ||
| description = 'Upload the Robolectric distribution package to S3' | ||
| dependsOn createRobolectricDistributionPackages | ||
| commandLine 's3cmd', 'put', "${buildDir}/outputs/distribution/realm-robolectric-darwin-${currentVersion}.zip", 's3://static.realm.io/downloads/java/' | ||
| } | ||
|
|
||
| task createEmptyFile(type: Exec) { | ||
| group = 'Release' | ||
| description = 'Create an empty file that will serve as a link on S3' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.zip |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| apply plugin: 'android-sdk-manager' | ||
| apply plugin: 'com.android.application' | ||
| apply plugin: 'android-command' | ||
| apply plugin: 'com.neenbedankt.android-apt' | ||
| apply plugin: 'realm-android' | ||
| apply plugin: 'realm-robolectric' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this as a separate plugin? I guess the main benefit is that people not using Robolectrics aren't forced to download any extra files, but on the downside they have to add this extra line. I'm a probably leaning towards this is OK, but what do you think @realm/java ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think most developers does not need the support for Robolectric for Darwin. They can use other unit test tools, they can use Mockup objects or even they don't use any unit test tool. So I want this as a separate plugin not to bother other developers.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well the plugin will hopefully work for both Windows and Linux soon :), but I get your point. It is probably only a minority that wants to use Robolectrics.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separate plugin +1 |
||
|
|
||
| android { | ||
| compileSdkVersion rootProject.sdkVersion | ||
| buildToolsVersion rootProject.buildTools | ||
|
|
||
| defaultConfig { | ||
| applicationId 'io.realm.examples.robolectric' | ||
| targetSdkVersion 21 | ||
| minSdkVersion 15 | ||
| versionCode 1 | ||
| versionName "1.0" | ||
| } | ||
| buildTypes { | ||
| release { | ||
| minifyEnabled false | ||
| } | ||
| } | ||
|
|
||
| command { | ||
| events 2000 | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| compile fileTree(dir: 'libs', include: ['*.jar']) | ||
| compile 'com.android.support:appcompat-v7:23.1.0' | ||
| compile 'com.android.support:design:23.1.0' | ||
| testCompile 'io.reactivex:rxjava:1.1.0' | ||
| testCompile 'junit:junit:4.12' | ||
| testCompile "org.robolectric:robolectric:3.0" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="io.realm.examples.robolectric" > | ||
|
|
||
| <application | ||
| android:allowBackup="true" | ||
| android:icon="@drawable/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme" > | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/AppTheme.NoActionBar" > | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| </application> | ||
|
|
||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Copyright 2016 Realm Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.realm.examples.robolectric; | ||
|
|
||
| import android.app.Activity; | ||
| import android.os.Bundle; | ||
|
|
||
| public class MainActivity extends Activity { | ||
|
|
||
| @Override | ||
| protected void onCreate(Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
| setContentView(R.layout.activity_main); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <android.support.design.widget.CoordinatorLayout | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:fitsSystemWindows="true" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <android.support.design.widget.AppBarLayout | ||
| android:layout_height="wrap_content" | ||
| android:layout_width="match_parent" | ||
| android:theme="@style/AppTheme.AppBarOverlay"> | ||
|
|
||
| <android.support.v7.widget.Toolbar | ||
| android:id="@+id/toolbar" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="?attr/actionBarSize" | ||
| android:background="?attr/colorPrimary" | ||
| app:popupTheme="@style/AppTheme.PopupOverlay"/> | ||
|
|
||
| </android.support.design.widget.AppBarLayout> | ||
|
|
||
| <include layout="@layout/content_main"/> | ||
|
|
||
| <android.support.design.widget.FloatingActionButton | ||
| android:id="@+id/fab" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content" | ||
| android:layout_gravity="bottom|end" | ||
| android:layout_margin="@dimen/fab_margin" | ||
| android:src="@android:drawable/ic_dialog_email"/> | ||
|
|
||
| </android.support.design.widget.CoordinatorLayout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <RelativeLayout | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="match_parent" | ||
| android:paddingLeft="@dimen/activity_horizontal_margin" | ||
| android:paddingRight="@dimen/activity_horizontal_margin" | ||
| android:paddingTop="@dimen/activity_vertical_margin" | ||
| android:paddingBottom="@dimen/activity_vertical_margin" | ||
| app:layout_behavior="@string/appbar_scrolling_view_behavior" | ||
| tools:showIn="@layout/activity_main" | ||
| tools:context=".MainActivity"> | ||
|
|
||
| <TextView | ||
| android:text="Hello World!" | ||
| android:layout_width="wrap_content" | ||
| android:layout_height="wrap_content"/> | ||
| </RelativeLayout> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto" | ||
| xmlns:tools="http://schemas.android.com/tools" | ||
| tools:context=".MainActivity"> | ||
| <item android:id="@+id/action_settings" | ||
| android:title="@string/action_settings" | ||
| android:orderInCategory="100" | ||
| app:showAsAction="never"/> | ||
| </menu> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <resources> | ||
| <style name="AppTheme.NoActionBar"> | ||
| <item name="windowActionBar">false</item> | ||
| <item name="windowNoTitle">true</item> | ||
| <item name="android:windowDrawsSystemBarBackgrounds">true</item> | ||
| <item name="android:statusBarColor">@android:color/transparent</item> | ||
| </style> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <resources> | ||
| <!-- Example customization of dimensions originally defined in res/values/dimens.xml | ||
| (such as screen margins) for screens with more than 820dp of available width. This | ||
| would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). --> | ||
| <dimen name="activity_horizontal_margin">64dp</dimen> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <color name="colorPrimary">#3F51B5</color> | ||
| <color name="colorPrimaryDark">#303F9F</color> | ||
| <color name="colorAccent">#FF4081</color> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <resources> | ||
| <!-- Default screen margins, per the Android Design guidelines. --> | ||
| <dimen name="activity_horizontal_margin">16dp</dimen> | ||
| <dimen name="activity_vertical_margin">16dp</dimen> | ||
| <dimen name="fab_margin">16dp</dimen> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <resources> | ||
| <string name="app_name">RobolectricTest</string> | ||
| <string name="action_settings">Settings</string> | ||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <resources> | ||
|
|
||
| <!-- Base application theme. --> | ||
| <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
| <!-- Customize your theme here. --> | ||
| <item name="colorPrimary">@color/colorPrimary</item> | ||
| <item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
| <item name="colorAccent">@color/colorAccent</item> | ||
| </style> | ||
| <style name="AppTheme.NoActionBar"> | ||
| <item name="windowActionBar">false</item> | ||
| <item name="windowNoTitle">true</item> | ||
| </style> | ||
| <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/> | ||
| <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/> | ||
|
|
||
| </resources> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| * Copyright 2016 Realm Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.realm.examples.robolectric; | ||
|
|
||
| import android.app.Activity; | ||
| import android.content.Context; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.ExternalResource; | ||
| import org.junit.runner.RunWith; | ||
| import org.robolectric.Robolectric; | ||
| import org.robolectric.RobolectricGradleTestRunner; | ||
| import org.robolectric.annotation.Config; | ||
|
|
||
| import io.realm.examples.robolectric.entities.Person; | ||
| import io.realm.test.RealmRobolectricRule; | ||
| import io.realm.Realm; | ||
| import io.realm.RealmConfiguration; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| @RunWith(RobolectricGradleTestRunner.class) | ||
| @Config(constants = BuildConfig.class) | ||
| public class RobolectricTest { | ||
|
|
||
| private Realm realm; | ||
| private Activity context; | ||
| private RealmConfiguration config; | ||
|
|
||
| @Rule | ||
| public RealmRobolectricRule realmRobolectricRule = new RealmRobolectricRule(); | ||
|
|
||
| private Context getContext() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method should be below any fields (= below the @rule) |
||
| return context; | ||
| } | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| context = Robolectric.setupActivity(MainActivity.class); | ||
| config = new RealmConfiguration.Builder(getContext()).build(); | ||
| Realm.deleteRealm(config); | ||
| realm = Realm.getInstance(config); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| if (realm != null) { | ||
| realm.close(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsEmpty() { | ||
| assertTrue(realm.isEmpty()); | ||
| Person person = new Person(); | ||
| person.setName("Brad Pitt"); | ||
| person.setAge(52); | ||
| realm.beginTransaction(); | ||
| realm.copyToRealm(person); | ||
| realm.commitTransaction(); | ||
| assertFalse(realm.isEmpty()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now part of the Gradle plugin, so could be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for the development.