-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add robolectric basic sample #146
base: main
Are you sure you want to change the base?
Conversation
ui/robolectric/BasicSample/README.md
Outdated
This project uses the Gradle build system. You don't need an IDE to build and execute it but Android Studio is recommended. | ||
|
||
1. Download the project code, preferably using `git clone`. | ||
1. Open the Android SDK Manager (*Tools* Menu | *Android*) and make sure you have installed the *Android Support Repository* under *Extras*. (For more Information click [here](http://developer.android.com/tools/testing-support-library/index.html#setup)) |
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 step is not necessary for Robolectric... it might not be necessary for instrumentation tests now since we're in gMaven @slinzner ?
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.
Done
compileSdkVersion 26 | ||
buildToolsVersion rootProject.buildToolsVersion | ||
defaultConfig { | ||
applicationId "com.example.android.testing.robolectric.BasicSample" |
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.
I don't think application id's usually have capital letters in do they? Is this the pattern in the other samples?
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.
Yes, it matches the other examples (it matches the package name which is uppercase).
@Test | ||
public void createActivityFromIntent() { | ||
Intent intent = new Intent(RuntimeEnvironment.application, MainActivity.class); | ||
Robolectric.buildActivity(MainActivity.class, intent).setup().get(); |
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 isn't really asserting anything, for this to be valuable you really want to make some assertions, like, have the activity render some data in the test fields that you specified in the intent for example.
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.
Removed.
|
||
@Test | ||
public void pauseResumeActivity() { | ||
ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class); |
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.
I don't really like this kind of test as it is not demonstrating any behaviour.
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.
Removed
public void setUp() { | ||
Intent intent = new Intent(RuntimeEnvironment.application, ShowTextActivity.class); | ||
intent.putExtra(ShowTextActivity.KEY_EXTRA_MESSAGE, MESSAGE); | ||
activity = Robolectric.buildActivity(ShowTextActivity.class, intent).setup().get(); |
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.
Robolectric.setupActivity()
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.
I don't think it works with an intent does it?
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.
Overall LGTM. Please add licenses to all the files and make sure you use the correct date (2017) on the license.
@@ -0,0 +1,69 @@ | |||
/* | |||
* Copyright 2015, The Android Open Source Project |
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.
2017
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.
Done
@@ -0,0 +1,30 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<!-- | |||
~ Copyright (C) 2015 The Android Open Source Project |
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.
2017
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.
Done
--> | ||
<resources> | ||
<style name="AppTheme" parent="android:Theme.Holo.Light"/> | ||
</resources> |
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.
add newline
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.
Done
@@ -0,0 +1,37 @@ | |||
package com.example.android.testing.robolectric.BasicSample; |
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.
license missing
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.
Done
ext { | ||
buildToolsVersion = "25.0.0" | ||
supportLibVersion = "25.4.0" | ||
runnerVersion = "1.0.0" |
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.
remove
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.
Done
projects.conf
Outdated
@@ -1,5 +1,6 @@ | |||
integration/ServiceTestRuleSample | |||
runner/AndroidJunitRunnerSample | |||
ui/robolectric/BasicSample |
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 should be under unit/ not ui/
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.
Moved to unit/BasicRobolectricSample.
lintOptions { | ||
abortOnError false | ||
} | ||
testOptions { |
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.
Please add a comment to indicate that this is required in order for Robolectric to work
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.
Done
} | ||
|
||
ext { | ||
buildToolsVersion = "25.0.0" |
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.
Update this to the latest version, which I guess should be 26.0.0
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.
Done
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.
LGTM, thanks for the changes. Please run the ./test_all.sh script before submitting to make sure everything still works.
Checked ./test_all.sh : ALL TESTS PASS |
Curious if all of the tests passed on Oct 6, 2017, why was this never merged in? |
Add example tests using robolectric. Copied the espresso BasicSample as is, with some string substitutions.