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

Commit

Permalink
add assumed and ignored tests (#37)
Browse files Browse the repository at this point in the history
* add assumed and ignored tests

* fix review
  • Loading branch information
viclovsky authored Oct 24, 2019
1 parent afefa1d commit cd415ee
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ abstract class AllureLifecycle(private val reader: AllureResultsReader,
steps.forEach { AllureStorage.remove(it.uuid, StepResult::class.java) }
afterTestStop(this)
}

}

open fun writeTestCase() = writeTestCase(AllureStorage.getTest())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package io.qameta.allure.android

import org.junit.runner.Description
import org.junit.runner.Result
import org.junit.runner.notification.Failure
import org.junit.runner.notification.RunListener
import io.qameta.allure.android.model.Label
import io.qameta.allure.android.model.Status
import io.qameta.allure.android.model.StatusDetails
Expand All @@ -15,6 +11,11 @@ import io.qameta.allure.android.utils.getLabels
import io.qameta.allure.android.utils.getLinks
import io.qameta.allure.android.utils.getMethodDisplayName
import io.qameta.allure.android.utils.getPackage
import org.junit.Ignore
import org.junit.runner.Description
import org.junit.runner.Result
import org.junit.runner.notification.Failure
import org.junit.runner.notification.RunListener
import java.util.*
import java.util.concurrent.ConcurrentHashMap

Expand Down Expand Up @@ -74,19 +75,7 @@ open class AllureRunListener(private val lifecycle: AllureLifecycle = AllureComm
@Throws(Exception::class)
override fun testStarted(description: Description) {
// val uuid = AllureStorage.getTest()
val testResult = TestResult(
uuid = "${description.className}#${description.methodName}",
historyId = getHistoryId(description),
name = getMethodDisplayName(description),
fullName = "${description.className}.${description.methodName}",
links = getLinks(description),
labels = listOf(
Label("package", getPackage(description.testClass)),
Label("testClass", description.className),
Label("testMethod", description.methodName),
Label("suite", getClassDisplayName(description)))
+ getLabels(description)
)
val testResult = createTestResult(description)
with(lifecycle) {
scheduleTestCase(getContainer(description).uuid, testResult)
startTestCase(testResult.uuid)
Expand Down Expand Up @@ -142,8 +131,12 @@ open class AllureRunListener(private val lifecycle: AllureLifecycle = AllureComm
* @param failure describes the test that failed and the
* * [org.junit.AssumptionViolatedException] that was thrown
*/
override fun testAssumptionFailure(failure: Failure?) {
//not implemented
@Throws(Exception::class)
override fun testAssumptionFailure(failure: Failure) {
lifecycle.updateTestCase {
status = Status.fromThrowable(failure.exception)
statusDetails = StatusDetails.fromThrowable(failure.exception)
}
}

/**
Expand All @@ -153,8 +146,18 @@ open class AllureRunListener(private val lifecycle: AllureLifecycle = AllureComm
* @param description describes the test that will not be run
*/
@Throws(Exception::class)
override fun testIgnored(description: Description?) {
//not implemented
override fun testIgnored(description: Description) {
val testResult = createTestResult(description)
testResult.status = Status.SKIPPED
testResult.statusDetails = getIgnoredMessage(description)
testResult.start = System.currentTimeMillis()

with(lifecycle) {
scheduleTestCase(getContainer(description).uuid, testResult)
startTestCase(testResult.uuid)
stopTestCase(testResult.uuid)
writeTestCase(testResult.uuid)
}
}

protected open fun finalizeContainer(container: String?) {
Expand All @@ -179,4 +182,25 @@ open class AllureRunListener(private val lifecycle: AllureLifecycle = AllureComm
return container
}

}
private fun getIgnoredMessage(description: Description): StatusDetails {
val ignore = description.getAnnotation(Ignore::class.java)
val message = if (ignore?.value?.isNotEmpty() == true)
ignore.value else "Test ignored (without reason)!"

return StatusDetails(message = message)
}

private fun createTestResult(description: Description): TestResult = TestResult(
uuid = "${description.className}#${description.methodName}",
historyId = getHistoryId(description),
name = getMethodDisplayName(description),
fullName = "${description.className}.${description.methodName}",
links = getLinks(description),
labels = listOf(
Label("package", getPackage(description.testClass)),
Label("testClass", description.className),
Label("testMethod", description.methodName),
Label("suite", getClassDisplayName(description)))
+ getLabels(description)
)
}
1 change: 1 addition & 0 deletions allure-android-model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'kotlin'

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
implementation "junit:junit:${jUnitVersion}"
implementation "com.google.code.gson:gson:${gsonVersion}"

testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.qameta.allure.android.model

import com.google.gson.annotations.SerializedName
import org.junit.AssumptionViolatedException

/**
* @author Badya on 14.04.2017.
Expand All @@ -22,6 +23,7 @@ enum class Status(val s: String) {
fun fromThrowable(e: Throwable?): Status {
when (e) {
is AssertionError -> return FAILED
is AssumptionViolatedException -> return SKIPPED
else -> return BROKEN
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import io.qameta.allure.espresso.FailshotRule
import io.qameta.allure.espresso.LogcatClearRule
import io.qameta.allure.espresso.LogcatDumpRule
import io.qameta.allure.espresso.WindowHierarchyRule
import org.junit.Assume
import org.junit.Ignore
import kotlin.test.assertTrue
import kotlin.test.fail

Expand Down Expand Up @@ -49,4 +51,21 @@ class AllureTest {
fun shouldAddAnnotations() {
assertTrue(true)
}

@Ignore("Some reason")
@Test
fun shouldIgnoredWithSomeReason() {
assertTrue(true)
}

@Test
@Ignore
fun shouldIgnored() {
assertTrue(true)
}

@Test
fun shouldAssumed() {
Assume.assumeTrue(false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class AllureAndroidListener : InstrumentationRunListener() {
override fun testFailure(failure: Failure) {
if (failure.description.isTest) {
val uuid = "${failure.description.className}#${failure.description.methodName}"
testFailed(uuid, failure)
testWithException(uuid, failure)
} else {
suiteFailed(failure)
suiteWithException(failure)
}
}

Expand All @@ -43,7 +43,20 @@ class AllureAndroidListener : InstrumentationRunListener() {
allureListenerDelegate.testRunFinished()
}

private fun testFailed(uuid: String, failure: Failure) {
override fun testIgnored(description: Description) {
allureListenerDelegate.testIgnored(description)
}

override fun testAssumptionFailure(failure: Failure) {
if (failure.description.isTest) {
val uuid = "${failure.description.className}#${failure.description.methodName}"
testWithException(uuid, failure)
} else {
suiteWithException(failure)
}
}

private fun testWithException(uuid: String, failure: Failure) {
with(lifecycle) {
updateTestCase(uuid) {
status = Status.fromThrowable(failure.exception)
Expand All @@ -53,10 +66,10 @@ class AllureAndroidListener : InstrumentationRunListener() {
}
}

private fun suiteFailed(failure: Failure) {
private fun suiteWithException(failure: Failure) {
failure.description.children.forEach {
val uuid = "${it.className}#${it.methodName}"
testFailed(uuid, failure)
testWithException(uuid, failure)
}
}

Expand Down

0 comments on commit cd415ee

Please sign in to comment.