This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Android Instrumented Test Environment
This commit adds android instrumented test environment. We need to test and know whether caver-java-android lib is well-working on real android machine or not. For this 1 > Add android_instrumented_test sub-project This sub-project is made for instrumented testing. This sub-project will use unit test files already written at core. This sub-project uses AndroidX Test Library for instrumented test. 2 > Add Suite Test for TestClasses containing nested classes This makes AndroidX Test Library well works on TestClass which contains nested classes. Without it, test cases of nested classes does not work on emulator. 3 > Update circle-ci config and add shell script To re-use unit tests written at core, I added a script for it and updated config of circle-ci too. 4 > Update git ignore To make android_instrumented_test which is Android Project works well, we must not ignore `gradle.properties` because it contains essentials of AndroidX Test Library.
- Loading branch information
Showing
42 changed files
with
374 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/sh | ||
|
||
PROJECT_DIR=~/circleci-caver-java-android | ||
|
||
CORE_DIR=$PROJECT_DIR/core | ||
CORE_TEST_DIR=$PROJECT_DIR/core/src/test | ||
CORE_TEST_CAVER_DIR=$CORE_TEST_DIR/java/com/klaytn/caver | ||
|
||
ANDROID_DIR=$PROJECT_DIR/android_instrumented_test | ||
ANDROID_TEST_DIR=$ANDROID_DIR/src/androidTest | ||
ANDROID_TEST_CAVER_DIR=$ANDROID_TEST_DIR/java/com/klaytn/caver/android_instrumented_test | ||
|
||
mkdir -p $ANDROID_TEST_CAVER_DIR | ||
|
||
## To do instrumented tests on Android Emulator, we use test files we already have at `core/src/test/java/com.klaytn.caver/*`. | ||
# 1. Copy unit test files of core to re-use without re-writing same test-cases just for instrumented test. | ||
cp -r $CORE_TEST_CAVER_DIR/base $ANDROID_TEST_CAVER_DIR/ | ||
cp -r $CORE_TEST_CAVER_DIR/common $ANDROID_TEST_CAVER_DIR/ | ||
|
||
# 2. To make instrumented test works, we need to replace some contents. | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i 's/package com.klaytn.caver/package com.klaytn.caver.android_instrumented_test/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i 's/import static com.klaytn.caver/import static com.klaytn.caver.android_instrumented_test/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i 's/import com.klaytn.caver.base/import com.klaytn.caver.android_instrumented_test.base/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i 's/Caver.DEFAULT_URL/"http:\/\/10.0.2.2:8551"/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i 's/localhost/10.0.2.2/g' | ||
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
PROJECT_DIR=/Users/denver.lee/klaytn/sdk-cell/github-aeharvlee/caver-java | ||
|
||
CORE_DIR=$PROJECT_DIR/core | ||
CORE_TEST_DIR=$PROJECT_DIR/core/src/test | ||
CORE_TEST_CAVER_DIR=$CORE_TEST_DIR/java/com/klaytn/caver | ||
|
||
ANDROID_DIR=$PROJECT_DIR/android_instrumented_test | ||
ANDROID_TEST_DIR=$ANDROID_DIR/src/androidTest | ||
ANDROID_TEST_CAVER_DIR=$ANDROID_TEST_DIR/java/com/klaytn/caver/android_instrumented_test | ||
|
||
mkdir -p $ANDROID_TEST_CAVER_DIR | ||
|
||
cp -r $CORE_TEST_CAVER_DIR/base $ANDROID_TEST_CAVER_DIR/ | ||
cp -r $CORE_TEST_CAVER_DIR/common $ANDROID_TEST_CAVER_DIR/ | ||
|
||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i '' 's/package com.klaytn.caver/package com.klaytn.caver.android_instrumented_test/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i '' 's/import static com.klaytn.caver/import static com.klaytn.caver.android_instrumented_test/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i '' 's/import com.klaytn.caver.base/import com.klaytn.caver.android_instrumented_test.base/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i '' 's/Caver.DEFAULT_URL/"http:\/\/10.0.2.2:8551"/g' | ||
find $ANDROID_TEST_CAVER_DIR -type f -name '*.java' | xargs sed -i '' 's/localhost/10.0.2.2/g' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
buildscript { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.3' | ||
} | ||
|
||
} | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
maven { url 'https://jitpack.io' } | ||
} | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.klaytn.caver.android_instrumented_test" | ||
minSdkVersion 24 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility 1.8 | ||
targetCompatibility 1.8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':core') | ||
androidTestImplementation "androidx.test.ext:junit:1.1.2" | ||
androidTestImplementation "junit:junit:$project.junitVersion" | ||
androidTestImplementation "androidx.test:runner:1.3.0" | ||
androidTestImplementation "androidx.test:rules:1.3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.klaytn.caver.android_instrumented_test"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<application android:usesCleartextTraffic="true"> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.