Skip to content
This repository was archived by the owner on Nov 16, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

apply plugin: 'shot'

apply from: rootProject.file('dependencies.gradle')
apply from: rootProject.file('versions.gradle')
apply from: rootProject.file('jacoco.gradle')
Expand All @@ -15,13 +18,16 @@ android {
targetSdkVersion versions.targetSdk
versionCode versions.code
versionName versions.name
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

testInstrumentationRunner "com.dvinc.notepad.ScreenshotTestRunner"

vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
minifyEnabled false
applicationIdSuffix '.debug'
// This line may produce Shot error when he tries download screenshots
//applicationIdSuffix '.debug'
versionNameSuffix '-DEBUG'
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
Expand Down Expand Up @@ -53,4 +59,11 @@ dependencies {
kapt(librariesAnnotaionProcessors)

implementation(appDependencies)

// Fix for: Generated not found *javax.annotation.processing.Generated*
compileOnly 'javax.annotation:jsr250-api:1.0'
}

shot {
appId = 'com.dvinc.notepad'
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions app/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dvinc.notepad"
android:sharedUserId="com.dvinc.notepad.uid">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

</manifest>

This file was deleted.

62 changes: 62 additions & 0 deletions app/src/androidTest/java/com/dvinc/notepad/MainScreenTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2020 by Denis Verentsov (decsent@yandex.ru)
* All rights reserved.
*/

package com.dvinc.notepad

import android.content.Context
import android.util.DisplayMetrics
import android.view.ContextThemeWrapper
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.ActivityTestRule
import com.dvinc.notepad.presentation.ui.main.MainActivity
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.ViewHelpers
import org.junit.Rule
import org.junit.Test

class MainScreenTest {

@get:Rule
var activityTestRule = ActivityTestRule<MainActivity>(MainActivity::class.java, false, false)

private val context = getInstrumentation().targetContext

private val contextWrapper = ContextThemeWrapper(context, R.style.AppTheme)

private val inflater = LayoutInflater.from(contextWrapper)

@Test
fun testEmptyNotepadList() {
val activity = activityTestRule.launchActivity(null)

Screenshot
.snapActivity(activity)
.record()
}

@Test
fun testEmptyNoteFragment() {
val noteFragment = inflater.inflate(R.layout.fragment_note, null, false)

compareScreenshot(noteFragment)
}

private fun compareScreenshot(view: View) {
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
ViewHelpers.setupView(view)
.setExactHeightPx(metrics.heightPixels)
.setExactWidthPx(metrics.widthPixels)
.layout()

Screenshot
.snap(view)
.record()
}
}
18 changes: 18 additions & 0 deletions app/src/androidTest/java/com/dvinc/notepad/ScreenshotTestRunner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dvinc.notepad

import android.os.Bundle
import androidx.test.runner.AndroidJUnitRunner
import com.facebook.testing.screenshot.ScreenshotRunner

class ScreenshotTestRunner : AndroidJUnitRunner() {

override fun onCreate(arguments: Bundle) {
ScreenshotRunner.onCreate(this, arguments)
super.onCreate(arguments)
}

override fun finish(resultCode: Int, results: Bundle) {
ScreenshotRunner.onDestroy()
super.finish(resultCode, results)
}
}
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.dvinc.notepad">
package="com.dvinc.notepad"
android:sharedUserId="com.dvinc.notepad.uid">
<!-- The line above is important for Shot plugin - it must be the same as in Manifest at androidTest folder. -->

<application
android:name=".NotepadApplication"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@color/black"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ buildscript {
ext.kotlin_version = '1.3.60'
ext.detekt_version = '1.0.0-RC14'
ext.spotless_version = '3.27.1'
ext.shot_version = '3.1.0'

repositories {
google()
Expand All @@ -16,6 +17,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$detekt_version"
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_version"
classpath "com.karumi:shot:$shot_version"
}
}

Expand Down
7 changes: 6 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def junit_version = '4.12'
def mockito_core_version = '2.18.0'
def kotlin_mockito_version = '2.1.0'
def android_arch_core_testing_version = '2.0.1'
def test_rules_version = '1.2.0'

def stetho_version = '1.5.0'
def timber_version = '4.7.1'
Expand Down Expand Up @@ -73,6 +74,10 @@ ext{
androidTestDependencies = [
test_runner = "com.android.support.test:runner:$test_runner_version",

espresso_core = "com.android.support.test.espresso:espresso-core:$espresso_core_version"
espresso_core = "com.android.support.test.espresso:espresso-core:$espresso_core_version",

test_rules = "androidx.test:rules:$test_rules_version",

kotlin_mockito = "com.nhaarman.mockitokotlin2:mockito-kotlin:$kotlin_mockito_version"
]
}