Skip to content

Commit

Permalink
Merge pull request #22 from allure-framework/feature/allure-android-s…
Browse files Browse the repository at this point in the history
…ample

Allure Android Sample
  • Loading branch information
viclovsky authored Jul 13, 2020
2 parents 0f8c10f + cfd8463 commit 44d0151
Show file tree
Hide file tree
Showing 39 changed files with 841 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @kamildziadek @viclovsky
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ $ git clone git@github.com:your-username/allure-kotlin.git
Then build the project (build requires JDK 1.6 or higher):

```bash
$ ./gradlew build
$ ./gradlew build -x :samples:junit4-android:testReleaseUnitTest -x :samples:junit4-android:testDebugUnitTest
```

Make your change. Add tests for your change. Make sure all the tests pass:

```bash
$ ./gradlew test
$ ./gradlew test -x :samples:junit4-android:testReleaseUnitTest -x :samples:junit4-android:testDebugUnitTest
```

Push your fork and submit a pull request.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
with:
java-version: 1.8
- name: "Build"
run: ./gradlew build
run: ./gradlew build -x :samples:junit4-android:testReleaseUnitTest -x :samples:junit4-android:testDebugUnitTest
13 changes: 13 additions & 0 deletions .github/workflows/label-verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Verify type labels"

on:
pull_request:
types: [opened, labeled, unlabeled, synchronize]

jobs:
triage:
runs-on: ubuntu-latest
steps:
- uses: zwaldowski/match-label-action@v2
with:
allowed: 'type:new feature, type:improvement, type:bug'
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
java-version: 1.8
- name: "Build"
run: ./gradlew build -Pversion=${GITHUB_REF:10}
run: ./gradlew build -x :samples:junit4-android:testReleaseUnitTest -x :samples:junit4-android:testDebugUnitTest -Pversion=${GITHUB_REF:10}
- name: "Publish"
run: ./gradlew publish -Pversion=${GITHUB_REF:10}
env:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.qameta.allure.android.listeners

import io.qameta.allure.android.internal.requestExternalStoragePermissions
import org.junit.runner.*
import org.junit.runner.notification.*

class ExternalStoragePermissionsListener : RunListener() {
override fun testRunStarted(description: Description?) {
requestExternalStoragePermissions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.test.runner.AndroidJUnitRunner
import io.qameta.allure.android.AllureAndroidLifecycle
import io.qameta.allure.android.internal.isDeviceTest
import io.qameta.allure.android.internal.requestExternalStoragePermissions
import io.qameta.allure.android.listeners.ExternalStoragePermissionsListener
import io.qameta.allure.kotlin.Allure
import io.qameta.allure.kotlin.junit4.AllureJunit4
import org.junit.runner.*
Expand All @@ -29,7 +30,12 @@ class AllureAndroidJUnit4(clazz: Class<*>) : Runner(), Filterable, Sortable {
}

private fun createListener(): RunListener? =
if (isDeviceTest()) createDeviceListener() else createRobolectricListener()
if (isDeviceTest()) {
requestExternalStoragePermissions()
createDeviceListener()
} else {
createRobolectricListener()
}

/**
* Creates listener for the tests running on a device.
Expand All @@ -44,7 +50,6 @@ class AllureAndroidJUnit4(clazz: Class<*>) : Runner(), Filterable, Sortable {
if (Allure.lifecycle == AllureAndroidLifecycle) return null

Allure.lifecycle = AllureAndroidLifecycle
requestExternalStoragePermissions()
return AllureJunit4(AllureAndroidLifecycle)
}

Expand Down Expand Up @@ -72,17 +77,13 @@ open class AllureAndroidJUnitRunner : AndroidJUnitRunner() {
Allure.lifecycle = AllureAndroidLifecycle
val listenerArg = listOfNotNull(
arguments.getCharSequence("listener"),
ExternalStoragePermissionsListener::class.java.name,
AllureJunit4::class.java.name
).joinToString(separator = ",")
arguments.putCharSequence("listener", listenerArg)
super.onCreate(arguments)
}

override fun onStart() {
super.onStart()
requestExternalStoragePermissions()
}

}

/**
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ allprojects {
val gradleScriptDir by extra("${rootProject.projectDir}/gradle")

configure(subprojects
.filter { !it.name.contains("android") }
.filter { !it.name.contains("android") }
.filter { it.parent?.name != "samples" }
) {
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(from = "$gradleScriptDir/maven-publish.gradle")
Expand Down
54 changes: 54 additions & 0 deletions samples/junit4-android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id("com.android.application")
id("kotlin-android")
}

android {
compileSdkVersion(Versions.Android.compileSdk)
defaultConfig {
applicationId = "io.qameta.allure.sample.junit4.android"
minSdkVersion(Versions.Android.minSdk)
targetSdkVersion(Versions.Android.targetSdk)
versionCode = 1
versionName = version as String

testInstrumentationRunner = "io.qameta.allure.android.runners.AllureAndroidJUnitRunner"
testInstrumentationRunnerArguments(mapOf("clearPackageData" to "true"))
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}

sourceSets {
val sharedTestDir = "src/sharedTest/java"
getByName("test").java.srcDir(sharedTestDir)
getByName("androidTest").java.srcDir(sharedTestDir)
}

testOptions.unitTests.isIncludeAndroidResources = true
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(kotlin("stdlib-jdk7", Versions.kotlin))

implementation("androidx.appcompat:appcompat:${Versions.Android.androidX}")
implementation("androidx.core:core-ktx:${Versions.Android.androidX}")

listOf(
project(":allure-kotlin-android"),
"androidx.test.ext:junit:${Versions.Android.Test.junit}",
"androidx.test:runner:${Versions.Android.Test.runner}",
"junit:junit:${Versions.junit4}",
"androidx.test.espresso:espresso-core:${Versions.Android.Test.espresso}"
).forEach {
testImplementation(it)
androidTestImplementation(it)
}

testImplementation("org.robolectric:robolectric:${Versions.Android.Test.robolectric}")
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.qameta.allure.android.listeners.LogcatContainerListener
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.qameta.allure.android.listeners.LogcatStepLifecycleListener
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.qameta.allure.android.listeners.LogcatTestLifecycleListener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allure.results.directory=allure-results
allure.link.issue.pattern=https://jira.domain-name.com/browse/{}
7 changes: 7 additions & 0 deletions samples/junit4-android/src/debug/AndroidManifest.xml
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="io.qameta.allure.sample.junit4.android">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
22 changes: 22 additions & 0 deletions samples/junit4-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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="io.qameta.allure.sample.junit4.android">

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".SampleActivity"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CrashActivity"
android:theme="@style/AppTheme.NoActionBar" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.qameta.allure.sample.junit4.android

import android.os.Bundle
import android.widget.Button
import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatActivity
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

class CrashActivity : AppCompatActivity() {

private val crashImmediate: Button
get() = findViewById(R.id.button_crash_immediate)
private val crashAsync: Button
get() = findViewById(R.id.button_crash_async)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_crash)

crashImmediate.setOnClickListener {
throw IllegalStateException("Crashing on purpose!")
}
crashAsync.setOnClickListener {
Executors.newSingleThreadExecutor().execute {
Thread.sleep(ASYNC_CRASH_TIME_MS)
throw IllegalStateException("Crashing async on purpose!")
}
}
}

companion object {
@VisibleForTesting
val ASYNC_CRASH_TIME_MS: Long = TimeUnit.SECONDS.toMillis(1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.qameta.allure.sample.junit4.android

import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class SampleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_sample)

findViewById<Button>(R.id.button_some).setOnClickListener {
findViewById<TextView>(R.id.label_some).text = getString(R.string.after_click)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.qameta.allure.sample.junit4.android

class SampleCalculator {
fun add(x: Int, y: Int): Int = x + y
fun subtract(x: Int, y: Int): Int = x - y
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeWidth="1"
android:strokeColor="#00000000">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
Loading

0 comments on commit 44d0151

Please sign in to comment.