Skip to content
Merged
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<img src="https://img.shields.io/badge/Support-%3E%3D%20Android%206.0-brightgreen" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several things pending to change in the README, I will do it at the end

</p>

# Android Loggerazzi
# Android Snaptesting

Logs snapshot testing for Android Instrumentation tests.
Logs and screenshots snapshot testing for Android Instrumentation tests.

## Introduction

Expand All @@ -22,14 +22,14 @@ To include the plugin, add it to the plugins block of your project's build.gradl
```gradle
plugins {
...
id("com.telefonica.loggerazzi-plugin") version $loggerazzi_version apply false
id("com.telefonica.androidsnaptesting-plugin") version $android_snaptesting_version apply false
}
```
Then, include it into your specific application or library build.gradle:
```gradle
plugins {
...
id "com.telefonica.loggerazzi-plugin"
id "com.telefonica.androidsnaptesting-plugin"
}
```

Expand All @@ -38,7 +38,7 @@ Also, include the rule dependency in your application or library dependencies bl
```gradle
dependencies {
...
androidTestImplementation "com.telefonica:loggerazzi:$loggerazzi_version"
androidTestImplementation "com.telefonica:androidsnaptesting:$android_snaptesting_version"
}
```

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
namespace = "com.telefonica.loggerazzi"
namespace = "com.telefonica.androidsnaptesting"
compileSdk = libs.versions.compile.sdk.get().toInt()


Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import android.graphics.Bitmap
import com.dropbox.differ.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting


@Retention(AnnotationRetention.RUNTIME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import java.lang.StringBuilder

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

public interface LogsRecorder<LogType> {
public fun clear()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import android.os.Environment
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.rules.TestWatcher
import org.junit.runner.Description
import java.io.File

public class LoggerazziRule(
public class LogsRule(
recorder: LogsRecorder<String>,
comparator: LogComparator<String> = DefaultLogComparator(),
) : GenericLoggerazziRule<String>(
) : GenericLogsRule<String>(
recorder = recorder,
stringMapper = object : StringMapper<String> {
override fun fromLog(log: String): String = log
Expand All @@ -18,7 +18,7 @@ public class LoggerazziRule(
comparator = comparator,
)

public open class GenericLoggerazziRule<LogType>(
public open class GenericLogsRule<LogType>(
public val recorder: LogsRecorder<LogType>,
private val stringMapper: StringMapper<LogType>,
private val comparator: LogComparator<LogType> = DefaultLogComparator(),
Expand All @@ -29,9 +29,9 @@ public open class GenericLoggerazziRule<LogType>(
private val downloadDir = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
)
private val loggerazziDir = File(downloadDir, "loggerazzi-logs/${context.packageName}")
private val failuresDir = File(loggerazziDir, "failures")
private val recordedDir = File(loggerazziDir, "recorded")
private val androidSnaptestingDir = File(downloadDir, "android-snaptesting/${context.packageName}")
private val failuresDir = File(androidSnaptestingDir, "failures")
private val recordedDir = File(androidSnaptestingDir, "recorded")

override fun starting(description: Description?) {
super.starting(description)
Expand Down Expand Up @@ -62,7 +62,7 @@ public open class GenericLoggerazziRule<LogType>(
if (InstrumentationRegistry.getArguments().getString("record") != "true" && !isTestIgnored) {
val goldenFile =
InstrumentationRegistry.getInstrumentation().context.assets.open(
"loggerazzi-golden-files/${testName}.txt"
"android-snaptesting-golden-files/${testName}.txt"
)
val goldenStringLogs = String(goldenFile.readBytes()).takeIf { it.isNotEmpty() }?.split("\n") ?: emptyList()
val result = comparator.compare(recordedLogs, goldenStringLogs.map { stringMapper.toLog(it) })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import com.dropbox.differ.ImageComparator
import kotlin.math.roundToInt
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import android.app.Activity
import android.graphics.Bitmap
Expand Down Expand Up @@ -35,9 +35,9 @@ public class ScreenshotsRule(
private val downloadDir = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath
)
private val loggerazziDir = File(downloadDir, "loggerazzi-logs/${context.packageName}")
private val failuresDir = File(loggerazziDir, "failures")
private val recordedDir = File(loggerazziDir, "recorded")
private val androidSnaptestingDir = File(downloadDir, "android-snaptesting/${context.packageName}")
private val failuresDir = File(androidSnaptestingDir, "failures")
private val recordedDir = File(androidSnaptestingDir, "recorded")

override fun apply(base: Statement, description: Description): Statement {
className = description.className
Expand Down Expand Up @@ -97,7 +97,7 @@ public class ScreenshotsRule(

private fun getGoldenBitmap(resourceName: String): Bitmap {
val goldenBitmap = try {
context.assets.open("loggerazzi-golden-files/$resourceName").use {
context.assets.open("android-snaptesting-golden-files/$resourceName").use {
BitmapFactory.decodeStream(it)
}
} catch (e: FileNotFoundException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

public interface StringMapper<LogType> {
public fun fromLog(log: LogType): String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import android.graphics.Bitmap
import android.graphics.Canvas
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin)
id("com.telefonica.loggerazzi-plugin")
id("com.telefonica.androidsnaptesting-plugin")
}

android {
namespace = "com.telefonica.loggerazzi"
namespace = "com.telefonica.androidsnaptesting"
compileSdk = libs.versions.compile.sdk.get().toInt()

defaultConfig {
applicationId = "com.telefonica.loggerazzi"
applicationId = "com.telefonica.androidsnaptesting"
minSdk = libs.versions.min.sdk.get().toInt()
targetSdk = libs.versions.target.sdk.get().toInt()
versionCode = 1
Expand Down Expand Up @@ -44,5 +44,5 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.espresso.junit)
androidTestImplementation(libs.espresso.core)
androidTestImplementation(project(":loggerazzi"))
androidTestImplementation(project(":android-snaptesting"))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand All @@ -17,7 +17,7 @@ class ExampleInstrumentedTest {
private val recorder = FakeTestRecorder()

@get:Rule
val loggerazziRule = LoggerazziRule(
val logsRule = LogsRule(
recorder = recorder
)
@get:Rule
Expand All @@ -42,13 +42,13 @@ class ExampleInstrumentedTest {

@Test
@IgnoreLogs
fun testIgnoreLoggerazzi() {
fun testIgnoreLogs() {
recorder.record("My log")
}

@Test
@IgnoreLogs
fun testIgnoreLoggerazziWithoutGoldenFile() {
fun testIgnoreLogsWithoutGoldenFile() {
recorder.record("My log")
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My log
Binary file not shown.

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Loggerazzi"
android:theme="@style/Theme.AndroidSnaptesting"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name="com.telefonica.androidsnaptesting.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.telefonica.loggerazzi
package com.telefonica.androidsnaptesting

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context="com.telefonica.androidsnaptesting.MainActivity">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
Expand All @@ -15,4 +16,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a description"
app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Loggerazzi" parent="Theme.Material3.DayNight.NoActionBar">
<style name="Base.Theme.AndroidSnaptesting" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> -->
</style>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Loggerazzi</string>
<string name="app_name">Android Snaptesting</string>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.Loggerazzi" parent="Theme.Material3.DayNight.NoActionBar">
<style name="Base.Theme.AndroidSnaptesting" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
</style>

<style name="Theme.Loggerazzi" parent="Base.Theme.Loggerazzi" />
<style name="Theme.AndroidSnaptesting" parent="Base.Theme.AndroidSnaptesting" />
</resources>
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

allprojects {
group = "com.telefonica.loggerazzi"
group = "com.telefonica.androidsnaptesting"
version = System.getProperty("LIBRARY_VERSION") ?: "undefined"

apply(plugin = rootProject.libs.plugins.detekt.get().pluginId)
Expand Down
2 changes: 1 addition & 1 deletion include-build/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

allprojects {
group = "com.telefonica.loggerazzi"
group = "com.telefonica.androidsnaptesting"
version = System.getProperty("LIBRARY_VERSION") ?: "undefined"

apply(plugin = rootProject.libs.plugins.detekt.get().pluginId)
Expand Down
14 changes: 7 additions & 7 deletions include-build/gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ dependencies {

gradlePlugin {
plugins {
create("loggerazzi-plugin") {
id = "com.telefonica.loggerazzi-plugin"
displayName = "Loggerazzi"
description = "Logs snapshot testing for Android Instrumentation tests"
implementationClass = "com.telefonica.loggerazzi.LoggerazziPlugin"
website = "https://github.com/Telefonica/android-loggerazzi"
vcsUrl = "https://github.com/Telefonica/android-loggerazzi"
create("androidsnaptesting-plugin") {
id = "com.telefonica.androidsnaptesting-plugin"
displayName = "Android Snaptesting"
description = "Logs and screenshots snapshot testing for Android Instrumentation tests"
implementationClass = "com.telefonica.androidsnaptesting.AndroidSnaptestingPlugin"
website = "https://github.com/Telefonica/android-snaptesting"
vcsUrl = "https://github.com/Telefonica/android-snaptesting"
tags = listOf("android", "instrumentation", "testing", "logs")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.telefonica.androidsnaptesting

class AndroidSnaptestingNoDeviceProviderInstrumentTestTasksException : Exception(
"No device provider instrument test tasks found. Make sure you are applying the Android Snaptesting plugin after the Android app/library plugin."
)
Loading