Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

version 2.5.1 #5

Merged
merged 3 commits into from
Mar 3, 2018
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# IDEA
.idea
.idea/*
!.idea/runConfigurations/
*.iml

# Gradle
Expand All @@ -8,4 +9,5 @@ build
/local.properties

# Other
.DS_Store
.DS_Store

5 changes: 3 additions & 2 deletions allure-android/allure-android-lint.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<lint>
<issue id="AllowBackup" severity="ignore"/>
<issue id="InvalidPackage" severity="ignore"/>
<issue id="AllowBackup" severity="ignore"/>
<issue id="InvalidPackage" severity="ignore"/>
<issue id="GradleDependency" severity="informational"/>
</lint>
77 changes: 56 additions & 21 deletions allure-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,44 +1,79 @@
apply plugin: "com.android.library"
apply plugin: "kotlin-android"

dependencies {
compile project(":allure-model")
compile project(":allure-common")
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
compile "com.android.support:support-annotations:${supportVersion}"
compile "com.android.support.test:runner:${supportTestVersion}"
compile "com.android.support:multidex:${multidexVersion}"
compile "com.android.support.test.uiautomator:uiautomator-v18:${uiAutomatorVersion}"
compile "junit:junit:${jUnitVersion}"
buildscript {
apply from: '../gradle/versions.gradle'
apply from: '../gradle/common.gradle'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:${androidPlugin}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion

defaultConfig {
targetSdkVersion rootProject.compileSdkVersion
minSdkVersion rootProject.minSdkVersion
versionName rootProject.version
versionName rootProject.projectVersion

testInstrumentationRunner "ru.tinkoff.allure.android.AllureAndroidRunner"
}

lintOptions {
htmlReport true
abortOnError true
warningsAsErrors true
htmlReport false
abortOnError false
warningsAsErrors false
lintConfig file("${project.name}-lint.xml")
}

packagingOptions {
exclude "LICENSE.txt"
exclude "META-INF/LICENSE.txt"
exclude "META-INF/NOTICE.txt"
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
androidTest.java.srcDirs += "src/androidTest/kotlin"
main.java.srcDirs += 'src/main/kotlin'
espresso.java.srcDirs += 'src/espresso/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}

testBuildType 'espresso'
buildTypes {
espresso {
initWith debug
}
}
}

dependencies {
implementation project(':allure-model')
implementation project(':allure-common')
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
implementation "com.android.support:support-annotations:${supportVersion}"
implementation "com.android.support.test:runner:${supportTestVersion}"
implementation "com.android.support.test:rules:${supportTestVersion}"
implementation "com.android.support:multidex:${multidexVersion}"
implementation "com.android.support.test.uiautomator:uiautomator-v18:${uiAutomatorVersion}"
implementation "junit:junit:${jUnitVersion}"

androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}"
androidTestImplementation "com.android.support.test.espresso:espresso-core:${espressoVersion}"

espressoImplementation "com.android.support:appcompat-v7:${supportVersion}"
espressoImplementation "com.android.support.constraint:constraint-layout:1.0.2"
espressoImplementation "io.reactivex:rxjava:1.3.4"
}

task copyLibs(type: Copy) {
from configurations.compile
from configurations.testCompile
into 'libs'
}
16 changes: 8 additions & 8 deletions allure-android/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
ajc* <methods>;
}

-keepnames class ru.tinkoff.mobileutils.** { *; }
-keepnames class ru.tinkoff.mobileutils.allure.** { *; }
-keepnames class ru.tinkoff.mobileutils.utils.** { *; }
-keepnames interface ru.tinkoff.mobileutils.** { *; }
-keep class ru.tinkoff.mobileutils.** { *; }
-keep class ru.tinkoff.mobileutils.allure.** { *; }
-keep class ru.tinkoff.mobileutils.utils.** { *; }
-keep interface ru.tinkoff.mobileutils.** { *; }
-keepnames class ru.tinkoff.** { *; }
-keepnames class ru.tinkoff.allure.** { *; }
-keepnames class ru.tinkoff.utils.** { *; }
-keepnames interface ru.tinkoff.** { *; }
-keep class ru.tinkoff.** { *; }
-keep class ru.tinkoff.allure.** { *; }
-keep class ru.tinkoff.utils.** { *; }
-keep interface ru.tinkoff.** { *; }
7 changes: 7 additions & 0 deletions allure-android/src/androidTest/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:tools="http://schemas.android.com/tools"
package="ru.tinkoff.allure">

<uses-sdk tools:overrideLibrary="android.support.test.uiautomator.v18" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.tinkoff.allure

import android.content.Intent
import android.support.test.InstrumentationRegistry
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.action.ViewActions.click
import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class CrashTest {
@get:Rule
val activityRule = ActivityTestRule<CrashTestActivity>(CrashTestActivity::class.java, true, false)

// adb shell am instrument -w -r -e debug false -e class ru.tinkoff.allure.CrashTest#crash ru.tinkoff.allure.test/ru.tinkoff.allure.android.AllureAndroidRunner
@Test
fun crash() {
activityRule.launchActivity(Intent(InstrumentationRegistry.getTargetContext().applicationContext, CrashTestActivity::class.java))
onView(withId(R.id.crash_button)).perform(click())
}

// adb shell am instrument -w -r -e debug false -e class ru.tinkoff.allure.CrashTest#rxCrash ru.tinkoff.allure.test/ru.tinkoff.allure.android.AllureAndroidRunner
@Test
fun rxCrash() {
activityRule.launchActivity(Intent(InstrumentationRegistry.getTargetContext().applicationContext, CrashTestActivity::class.java))
onView(withId(R.id.rx_crash_button)).perform(click())
}
}
9 changes: 9 additions & 0 deletions allure-android/src/espresso/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
>

<application
android:theme="@style/Theme.AppCompat.DayNight">
<activity android:name="ru.tinkoff.allure.CrashTestActivity">
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ru.tinkoff.allure

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import rx.Observable
import rx.schedulers.Schedulers

class CrashTestActivity : AppCompatActivity() {

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

findViewById<Button>(R.id.crash_button).setOnClickListener {
stackOverflow()
}

findViewById<Button>(R.id.rx_crash_button).setOnClickListener {
rxCrash()
}
}

private fun stackOverflow() {
stackOverflow()
}

private fun rxCrash() {
Observable.error<RuntimeException>(RuntimeException())
.subscribeOn(Schedulers.io())
.subscribe(
/* onNext */ {},
/* onError */ {t:Throwable -> throw RuntimeException(t)},
/* onCompleted */ {})
}
}
37 changes: 37 additions & 0 deletions allure-android/src/espresso/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ru.tinkoff.allure.CrashTestActivity">

<Button
android:id="@+id/crash_button"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/crash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.265"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />

<Button
android:id="@+id/rx_crash_button"
android:layout_width="120dp"
android:layout_height="120dp"
android:text="@string/rx_crash"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/crash_button"
tools:layout_constraintBottom_creator="1"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintRight_creator="1"
tools:layout_constraintTop_creator="1" />
</android.support.constraint.ConstraintLayout>
4 changes: 4 additions & 0 deletions allure-android/src/espresso/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="crash">CRASH</string>
<string name="rx_crash">RX CRASH</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,35 +1,70 @@
package ru.tinkoff.allure.android

import android.support.annotation.Keep
import android.support.test.InstrumentationRegistry.getInstrumentation
import android.support.test.internal.runner.listener.InstrumentationRunListener
import android.support.test.uiautomator.UiDevice
import org.junit.runner.Description
import org.junit.runner.Result
import ru.tinkoff.allure.AllureLifecycle
import org.junit.runner.notification.Failure
import ru.tinkoff.allure.AllureRunListener
import ru.tinkoff.allure.model.Status
import ru.tinkoff.allure.model.StatusDetails

/**
* @author Badya on 05.06.2017.
*/
class AllureAndroidListener : InstrumentationRunListener() {
private val lifecycle = AllureAndroidLifecycle
private val allureListenerDelegate = AllureRunListener(lifecycle)

@Keep
class AllureAndroidListener : AllureRunListener() {
override val lifecycle: AllureLifecycle
get() = AllureAndroidLifecycle
override fun testStarted(description: Description) {
allureListenerDelegate.testStarted(description)
}

override fun testFinished(description: Description) {
allureListenerDelegate.testFinished(description)
}

override fun testFailure(failure: Failure) {
if (failure.description.isTest) {
val uuid = "${failure.description.className}#${failure.description.methodName}"
testFailed(uuid, failure)
} else {
suiteFailed(failure)
}
}

override fun testRunStarted(description: Description) {
override fun testRunStarted(description: Description?) {
grantPermissions()
super.testRunStarted()
allureListenerDelegate.testRunStarted()
}

override fun testRunFinished(result: Result?) {
allureListenerDelegate.testRunFinished()
}

private fun testFailed(uuid: String, failure: Failure) {
with(lifecycle) {
updateTestCase(uuid) {
status = Status.fromThrowable(failure.exception)
statusDetails = StatusDetails.fromThrowable(failure.exception)
}
writeTestCase(uuid)
}
}

override fun testRunFinished(result: Result) {
super.testRunFinished()
private fun suiteFailed(failure: Failure) {
failure.description.children.forEach {
val uuid = "${it.className}#${it.methodName}"
testFailed(uuid, failure)
}
}

private fun grantPermissions() {
UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm grant " + getInstrumentation().context.packageName + " android.permission.WRITE_EXTERNAL_STORAGE")
UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm grant " + getInstrumentation().targetContext.packageName + " android.permission.WRITE_EXTERNAL_STORAGE")
UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm grant " + getInstrumentation().context.packageName + " android.permission.READ_EXTERNAL_STORAGE")
UiDevice.getInstance(getInstrumentation()).executeShellCommand("pm grant " + getInstrumentation().targetContext.packageName + " android.permission.READ_EXTERNAL_STORAGE")
with(UiDevice.getInstance(instrumentation)) {
executeShellCommand("pm grant " + instrumentation.context.packageName + " android.permission.WRITE_EXTERNAL_STORAGE")
executeShellCommand("pm grant " + instrumentation.targetContext.packageName + " android.permission.WRITE_EXTERNAL_STORAGE")
executeShellCommand("pm grant " + instrumentation.context.packageName + " android.permission.READ_EXTERNAL_STORAGE")
executeShellCommand("pm grant " + instrumentation.targetContext.packageName + " android.permission.READ_EXTERNAL_STORAGE")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.tinkoff.allure.android

import android.support.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import android.support.test.internal.util.AndroidRunnerParams
import org.junit.runner.notification.RunNotifier
import org.junit.runners.model.InitializationError

/**
* @author b.mukvich on 05.06.2017.
*/
class AllureRunner
/**
* Constructs a new instance of the default runner
*/
@Throws(InitializationError::class)
constructor(klass: Class<*>, runnerParams: AndroidRunnerParams) : AndroidJUnit4ClassRunner(klass, runnerParams) {
override fun run(notifier: RunNotifier?) {

super.run(notifier)
}
}
Loading