File tree Expand file tree Collapse file tree
src/test/java/jp/studyplus/android/sdk/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
12apply plugin : ' android-library'
3+ apply plugin : ' android-test'
24
35android {
46 compileSdkVersion 19
@@ -10,11 +12,26 @@ android {
1012 versionCode 1
1113 versionName " 1.0"
1214 }
15+ sourceSets {
16+ instrumentTest. setRoot(' src/test' )
17+ }
18+ }
19+
20+ tasks. withType(Test ) {
21+ systemProperty " robolectric.logging" , " stdout"
1322}
1423
1524dependencies {
1625 compile ' com.android.support:appcompat-v7:19.0.1'
1726 compile ' com.google.guava:guava:16.0'
27+
28+ def forTesting = [
29+ ' junit:junit:4.11' ,
30+ ' org.robolectric:robolectric:2.3-SNAPSHOT' ,
31+ ' com.squareup:fest-android:1.0.7' ,
32+ ]
33+ forTesting. each{ testCompile it }
34+ forTesting. each{ instrumentTestCompile it }
1835}
1936
2037apply plugin : ' maven'
Original file line number Diff line number Diff line change 1+ package jp .studyplus .android .sdk .test ;
2+
3+ import org .junit .runner .notification .RunNotifier ;
4+ import org .junit .runners .model .FrameworkMethod ;
5+ import org .junit .runners .model .InitializationError ;
6+ import org .robolectric .AndroidManifest ;
7+ import org .robolectric .RobolectricTestRunner ;
8+ import org .robolectric .annotation .Config ;
9+ import org .robolectric .res .Fs ;
10+
11+ public class RobolectricGradleTestRunner extends RobolectricTestRunner {
12+
13+ public RobolectricGradleTestRunner (Class <?> testClass ) throws InitializationError {
14+ super (testClass );
15+ }
16+
17+ @ Override
18+ protected void runChild (FrameworkMethod method , RunNotifier notifier ) {
19+ super .runChild (method , notifier );
20+ }
21+
22+ @ Override
23+ protected AndroidManifest getAppManifest (Config config ) {
24+ String manifestProperty = System .getProperty ("android.manifest" );
25+ if (config .manifest ().equals (Config .DEFAULT ) && manifestProperty != null ) {
26+ String resProperty = System .getProperty ("android.resources" );
27+ String assetsProperty = System .getProperty ("android.assets" );
28+ return new AndroidManifest (
29+ Fs .fileFromPath (manifestProperty ),
30+ Fs .fileFromPath (resProperty ),
31+ Fs .fileFromPath (assetsProperty ));
32+ }
33+ return super .getAppManifest (config );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ package jp .studyplus .android .sdk .test ;
2+
3+ import android .app .Activity ;
4+
5+ import org .junit .Before ;
6+ import org .junit .Ignore ;
7+ import org .junit .runner .RunWith ;
8+ import org .robolectric .Robolectric ;
9+
10+ @ Ignore
11+ @ RunWith (RobolectricGradleTestRunner .class )
12+ public class RobolectricTest {
13+
14+ @ Before
15+ public void setUp (){
16+ Robolectric .checkActivities (true );
17+ }
18+
19+ protected Activity getActivity (){
20+ return Robolectric .buildActivity (Activity .class ).create ().get ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package jp .studyplus .android .sdk .test .auth ;
2+
3+ import android .content .ActivityNotFoundException ;
4+
5+ import org .junit .Test ;
6+
7+ import jp .studyplus .android .sdk .service .auth .AuthTransit ;
8+ import jp .studyplus .android .sdk .test .RobolectricTest ;
9+
10+ public class AuthTransitTest extends RobolectricTest {
11+
12+ @ Test (expected = ActivityNotFoundException .class )
13+ public void shouldThrowActivityNotFound () {
14+ AuthTransit .from (getActivity ()).startActivity ("dummy_key" , "dummy_key_secret" );
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ package jp .studyplus .android .sdk .test .service .api ;
2+
3+ import org .junit .Test ;
4+
5+ import jp .studyplus .android .sdk .service .api .ApiRequest ;
6+ import jp .studyplus .android .sdk .service .api .StudyplusApi ;
7+ import jp .studyplus .android .sdk .service .auth .AccessTokenNotFound ;
8+ import jp .studyplus .android .sdk .service .studyrecord .StudyRecordBuilder ;
9+ import jp .studyplus .android .sdk .service .studyrecord .StudyRecordPostRequest ;
10+ import jp .studyplus .android .sdk .test .RobolectricTest ;
11+
12+ public class StudyplusApiTest extends RobolectricTest {
13+
14+ @ Test (expected = AccessTokenNotFound .class )
15+ public void testCatchAccessToken (){
16+ ApiRequest request = StudyRecordPostRequest .of (new StudyRecordBuilder ().build ());
17+ StudyplusApi .getClient (getActivity ()).send (request );
18+ }
19+ }
Original file line number Diff line number Diff line change 22buildscript {
33 repositories {
44 mavenCentral()
5+ maven {
6+ url ' https://oss.sonatype.org/content/repositories/snapshots/'
7+ }
58 }
69 dependencies {
710 classpath ' com.android.tools.build:gradle:0.8.+'
11+ classpath ' com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
812 }
913}
1014
1115allprojects {
1216 repositories {
1317 mavenCentral()
18+ maven {
19+ url ' https://oss.sonatype.org/content/repositories/snapshots/'
20+ }
1421 }
1522}
You can’t perform that action at this time.
0 commit comments