Skip to content

Commit

Permalink
Merge pull request #56 from Malinskiy/feature/test-meta-listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy authored Oct 12, 2021
2 parents ef540ba + 7bbd0f5 commit fbcce6e
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 0 deletions.
64 changes: 64 additions & 0 deletions android-junit4-test-annotation-producer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2021 Anton Malinskiy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("com.android.library")
id("kotlin-android")
id("maven-publish")
id("org.jetbrains.dokka")
}

android {
compileSdk = 30

defaultConfig {
minSdk = 14
targetSdk = 30
}

sourceSets {
getByName("main") {
java.srcDir("src/main/kotlin")
}
getByName("test") {
java.srcDir("src/test/kotlin")
}
getByName("androidTest") {
java.srcDir("src/androidTest/kotlin")
}
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class) {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.apiVersion = "1.5"
}

dependencies {
implementation(kotlin("stdlib-jdk8", version = Versions.kotlin))
implementation(kotlin("reflect", version = Versions.kotlin))
api(TestLibraries.junit4)
api(AndroidX.testMonitor)
}

afterEvaluate {
Deployment.initialize(project)
}
16 changes: 16 additions & 0 deletions android-junit4-test-annotation-producer/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (C) 2021 Anton Malinskiy
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
android.useAndroidX=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2021 Anton Malinskiy
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<manifest package="com.malinskiy.adam.junit4.android.listener">

<application/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2021 Anton Malinskiy
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.malinskiy.adam.junit4.android.listener

import android.os.Bundle
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.runner.Description
import org.junit.runner.notification.RunListener
import kotlin.reflect.full.memberProperties

/**
* JUnit4 listener that produces test annotations, e.g. using am instrument:
* INSTRUMENTATION_STATUS_CODE: 0
* INSTRUMENTATION_STATUS: class=com.example.FailedAssumptionTest
* INSTRUMENTATION_STATUS: current=4
* INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
* INSTRUMENTATION_STATUS: numtests=39
* INSTRUMENTATION_STATUS: stream=
* com.example.FailedAssumptionTest:
* INSTRUMENTATION_STATUS: test=ignoreTest
* INSTRUMENTATION_STATUS_CODE: 1
* INSTRUMENTATION_STATUS: com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer.v2=[androidx.test.filters.SmallTest(), io.qameta.allure.kotlin.Severity(value=critical), io.qameta.allure.kotlin.Story(value=Slow), org.junit.Test(expected=class org.junit.Test$None:timeout=0), io.qameta.allure.kotlin.Owner(value=user2), io.qameta.allure.kotlin.Feature(value=Text on main screen), io.qameta.allure.kotlin.Epic(value=General), org.junit.runner.RunWith(value=class io.qameta.allure.android.runners.AllureAndroidJUnit4), kotlin.Metadata(bytecodeVersion=[I@bdf6b25:data1=[Ljava.lang.String;@46414fa:data2=[Ljava.lang.String;@5d4aab:extraInt=0:extraString=:kind=1:metadataVersion=[I@fbb1508:packageName=), io.qameta.allure.kotlin.Severity(value=critical), io.qameta.allure.kotlin.Story(value=Slow)]
* INSTRUMENTATION_STATUS_CODE: 2
* INSTRUMENTATION_STATUS: class=com.example.FailedAssumptionTest
* INSTRUMENTATION_STATUS: current=4
* INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
* INSTRUMENTATION_STATUS: numtests=39
* INSTRUMENTATION_STATUS: stream=.
* INSTRUMENTATION_STATUS: test=ignoreTest
*/
class TestAnnotationProducer : RunListener() {
override fun testStarted(description: Description?) {
super.testStarted(description)
if (description?.isTest == true) {
val annotations: List<String> =
(description.annotations.toList() + description.testClass.annotations.toList()).mapNotNull { annotation ->
val fqn = annotation.annotationClass.qualifiedName
val parameters =
annotation.annotationClass.memberProperties.joinToString(separator = ":") { "${it.name}=${it.getter.call(annotation)}" }
"$fqn($parameters)"
}
val bundle = Bundle(1)
bundle.putStringArrayList(
"com.malinskiy.adam.junit4.android.listener.TestAnnotationProducer.v2",
ArrayList(annotations)
)
InstrumentationRegistry.getInstrumentation().sendStatus(2, bundle)
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pluginManagement {
}
include(":adam")
include(":android-junit4")
include(":android-junit4-test-annotation-producer")
include(":android-testrunner-contract")
include(":server:server-stub")
include(":server:server-stub-junit4")
Expand Down

0 comments on commit fbcce6e

Please sign in to comment.