diff --git a/.travis.yml b/.travis.yml index 406c8de..15181aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,34 +2,64 @@ language: android jdk: oraclejdk8 env: global: - - ANDROID_API=29 - - ANDROID_BUILD_TOOLS=29.0.2 + - ABI="default;armeabi-v7a" + - ANDROID_BUILD_TOOLS=28.0.3 - ADB_INSTALL_TIMEOUT=5 + - EMULATOR_API_LEVEL=23 + - SYSTEM_IMAGE=/usr/local/android-sdk/system-images/android-23/default/armeabi-v7a/kernel-ranchu + - ANDROID_SDK_ROOT=/usr/local/android-sdk android: components: - tools - platform-tools - build-tools-$ANDROID_BUILD_TOOLS - - android-$ANDROID_API - android-$EMULATOR_API_LEVEL + - extra-google-google_play_services - extra-google-m2repository - extra-android-m2repository - - sys-img-armeabi-v7a-addon-google_apis-google-$ANDROID_API_LEVEL - - sys-img-armeabi-v7a-addon-google_apis-google-$EMULATOR_API_LEVEL + - sys-img-armeabi-v7a-android-$EMULATOR_API_LEVEL licenses: - android-sdk-preview-license-.+ - android-sdk-license-.+ - google-gdk-license-.+ + before_install: - chmod +x gradlew - chmod +x scripts/build_publish.sh - chmod +x scripts/build_compile.sh + # Android test (screenshot) commands init + - yes | sdkmanager --sdk_root=$ANDROID_SDK_ROOT "tools" "build-tools;$ANDROID_BUILD_TOOLS" "extras;android;m2repository" + - export ANDROID_SDK=$ANDROID_SDK_ROOT + - export PATH=$ANDROID_SDK/emulator:$ANDROID_SDK/tools:$PATH + - export PATH=$ANDROID_SDK/tools/bin:$PATH + # Android test (screenshot) commands end - ./gradlew dependencies || true +install: + # Android test (screenshot) commands init + - sudo -H pip install pillow + - sudo -H pip install pillowcase + # Android test (screenshot) commands end + +cache: + directories: + - $HOME/.cache/pip + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ +before_cache: + - rm -f $HOME/.cache/pip/log/debug.log + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ + before_script: - git lfs pull + - find /usr/local/android-sdk/system-images -type f + - echo no | android create avd --force -n test -k "system-images;android-$EMULATOR_API_LEVEL;$ABI" -c 100M + - emulator @test -kernel $SYSTEM_IMAGE -no-audio -no-window & + - android-wait-for-emulator + - adb shell input keyevent 82 & script: - ./scripts/build_publish.sh diff --git a/build.gradle b/build.gradle index 8202308..d7145eb 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.5.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.facebook.testing.screenshot:plugin:0.11.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -25,4 +26,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/scripts/build_publish.sh b/scripts/build_publish.sh index a396310..13f3574 100644 --- a/scripts/build_publish.sh +++ b/scripts/build_publish.sh @@ -8,6 +8,6 @@ if [ $TRAVIS_BRANCH = "master" -a $TRAVIS_PULL_REQUEST = "false" ]; then echo "We're on the master branch." else echo "We're not on the master branch." - ./gradlew clean build -PdisablePreDex --stacktrace + ./gradlew clean build :system:verifyDebugAndroidTestScreenshotTest -PdisablePreDex --stacktrace fi diff --git a/system/build.gradle b/system/build.gradle index e1671fd..4488d24 100644 --- a/system/build.gradle +++ b/system/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'com.facebook.testing.screenshot' apply from: "$rootDir/publish.gradle" android { @@ -13,7 +14,7 @@ android { versionCode 1 versionName "1.0" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "com.selem.system.ScreenShotTestRunner" consumerProguardFiles 'consumer-rules.pro' } diff --git a/system/screenshots/com.selem.system.ExampleInstrumentedTest_greenView_checkDefaultState.png b/system/screenshots/com.selem.system.ExampleInstrumentedTest_greenView_checkDefaultState.png new file mode 100644 index 0000000..70b09e0 Binary files /dev/null and b/system/screenshots/com.selem.system.ExampleInstrumentedTest_greenView_checkDefaultState.png differ diff --git a/system/src/androidTest/AndroidManifest.xml b/system/src/androidTest/AndroidManifest.xml new file mode 100644 index 0000000..0dbf00e --- /dev/null +++ b/system/src/androidTest/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/system/src/androidTest/java/com/selem/system/ExampleInstrumentedTest.kt b/system/src/androidTest/java/com/selem/system/ExampleInstrumentedTest.kt index b23d04c..2168947 100644 --- a/system/src/androidTest/java/com/selem/system/ExampleInstrumentedTest.kt +++ b/system/src/androidTest/java/com/selem/system/ExampleInstrumentedTest.kt @@ -2,6 +2,8 @@ package com.selem.system import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import com.facebook.testing.screenshot.Screenshot +import com.facebook.testing.screenshot.ViewHelpers import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith @@ -14,9 +16,18 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ExampleInstrumentedTest { @Test - fun useAppContext() { + fun greenView_checkDefaultState() { // Context of the app under test. val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.selem.system.test", appContext.packageName) +// assertEquals("com.selem.system.test", appContext.packageName) + + val greenView = GreenView(appContext) + + ViewHelpers.setupView(greenView) + .setExactWidthDp(300) + .setExactHeightDp(100) + .layout() + + Screenshot.snap(greenView).record() } } diff --git a/system/src/androidTest/java/com/selem/system/ScreenShotTestRunner.kt b/system/src/androidTest/java/com/selem/system/ScreenShotTestRunner.kt new file mode 100644 index 0000000..71beebe --- /dev/null +++ b/system/src/androidTest/java/com/selem/system/ScreenShotTestRunner.kt @@ -0,0 +1,17 @@ +package com.selem.system + +import android.os.Bundle +import androidx.test.runner.AndroidJUnitRunner +import com.facebook.testing.screenshot.ScreenshotRunner + +class ScreenShotTestRunner : AndroidJUnitRunner() { + override fun onCreate(arguments: Bundle?) { + super.onCreate(arguments) + ScreenshotRunner.onCreate(this, arguments) + } + + override fun finish(resultCode: Int, results: Bundle?) { + ScreenshotRunner.onDestroy() + super.finish(resultCode, results) + } +} \ No newline at end of file diff --git a/system/src/main/AndroidManifest.xml b/system/src/main/AndroidManifest.xml index 7facffd..5e92643 100644 --- a/system/src/main/AndroidManifest.xml +++ b/system/src/main/AndroidManifest.xml @@ -1 +1,5 @@ - + + + diff --git a/system/src/main/java/com/selem/system/GreenView.kt b/system/src/main/java/com/selem/system/GreenView.kt new file mode 100644 index 0000000..4cc7642 --- /dev/null +++ b/system/src/main/java/com/selem/system/GreenView.kt @@ -0,0 +1,16 @@ +package com.selem.system + +import android.content.Context +import android.graphics.drawable.ColorDrawable +import android.util.AttributeSet +import android.view.View +import androidx.core.content.ContextCompat + + +class GreenView @JvmOverloads constructor(context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0): View(context, attrs, defStyleAttr) { + init { + background = ColorDrawable(ContextCompat.getColor(context, android.R.color.holo_green_light)) + } +} \ No newline at end of file