File tree Expand file tree Collapse file tree 6 files changed +116
-0
lines changed
src/test/java/jp/studyplus/android/sdk/test Expand file tree Collapse file tree 6 files changed +116
-0
lines changed Original file line number Diff line number Diff line change
1
+
1
2
apply plugin : ' android-library'
3
+ apply plugin : ' android-test'
2
4
3
5
android {
4
6
compileSdkVersion 19
@@ -10,11 +12,26 @@ android {
10
12
versionCode 1
11
13
versionName " 1.0"
12
14
}
15
+ sourceSets {
16
+ instrumentTest. setRoot(' src/test' )
17
+ }
18
+ }
19
+
20
+ tasks. withType(Test ) {
21
+ systemProperty " robolectric.logging" , " stdout"
13
22
}
14
23
15
24
dependencies {
16
25
compile ' com.android.support:appcompat-v7:19.0.1'
17
26
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 }
18
35
}
19
36
20
37
apply 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 2
2
buildscript {
3
3
repositories {
4
4
mavenCentral()
5
+ maven {
6
+ url ' https://oss.sonatype.org/content/repositories/snapshots/'
7
+ }
5
8
}
6
9
dependencies {
7
10
classpath ' com.android.tools.build:gradle:0.8.+'
11
+ classpath ' com.squareup.gradle:gradle-android-test-plugin:0.9.1-SNAPSHOT'
8
12
}
9
13
}
10
14
11
15
allprojects {
12
16
repositories {
13
17
mavenCentral()
18
+ maven {
19
+ url ' https://oss.sonatype.org/content/repositories/snapshots/'
20
+ }
14
21
}
15
22
}
You can’t perform that action at this time.
0 commit comments