Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shouldThrow support for steps #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ There is a full setting table. All settings adjust by system variable:
| allure.slf4j.log | duplicate allure step and attachment messages to Slf4j Logger | true |
| allure.lifecycle.class | Set `AllureLifecycle` full class name | `ru.iopump.kotest.allure.api.Slf4JAllureLifecycle`|
| kotest.allure.data.driven | Create new Allure test case on each new iteration in Data Driven tests or Property Testing | true |
| kotest.allure.step.shouldThrow ⚡NEW⚡ | Doesn't break test if step throws exception in shouldThrow block | true |
| kotest.allure.meta.cleanup ⚡NEW⚡ | Clean all allure metadata (issue, tms, allureId) from test case name. `"My test name [JIRA-1](TMS-2)#3 - { ... }` - will be cleaned up to `"My test name"` in report. | true |

All variables are very flexible, for example: `allure.jira.pattern` == `allure_jira_pattern` == `ALLURE.JIRA.PATTERN` == `ALLURE_JIRA_PATTERN` as `ENV` or `SYS` variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ object KotestAllureConstant {
*/
const val DATA_DRIVEN_SUPPORT = "kotest.allure.data.driven"

/**
* Enable shouldThrow support: doesn't break test if step throws exception in shouldThrow block
*
* Default = true - enable. (disable it if face unexpected behavior)
*/
const val STEP_SHOULD_THROW_SUPPORT = "kotest.allure.step.shouldThrow"

/**
* Clean all allure metadata (issue, tms, allureId) from test case name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import io.kotest.core.source.SourceRef.ClassSource
import io.kotest.core.source.SourceRef.FileSource
import io.kotest.core.source.SourceRef.None
import io.kotest.core.test.TestResult.Success
import io.kotest.core.test.TestStatus
import io.qameta.allure.model.StepResult
import ru.iopump.kotest.allure.KotestAllureListener.log
import ru.iopump.kotest.allure.api.KotestAllureConstant.VAR.DATA_DRIVEN_SUPPORT
Expand Down Expand Up @@ -177,5 +176,5 @@ object InternalExecutionModel {

private val KotestTestCase.parentUuid: String? get() = testUuidMap[descriptor.parent]

private val KotestTestResult.needPassOnTop: Boolean get() = status in arrayOf(TestStatus.Error, TestStatus.Failure)
private val KotestTestResult.needPassOnTop: Boolean get() = isErrorOrFailure
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.opentest4j.TestAbortedException
import org.slf4j.LoggerFactory
import ru.iopump.kotest.allure.api.KotestAllureConstant
import ru.iopump.kotest.allure.api.KotestAllureConstant.VAR.SKIP_ON_FAIL
import ru.iopump.kotest.allure.api.KotestAllureConstant.VAR.STEP_SHOULD_THROW_SUPPORT
import ru.iopump.kotest.allure.api.KotestAllureConstant.VAR.TEST_NAME_AUTO_CLEAN_UP
import ru.iopump.kotest.allure.api.KotestAllureExecution.bestName
import ru.iopump.kotest.allure.helper.meta.AllureMetadata
Expand All @@ -27,6 +28,8 @@ internal object InternalUtil {

private val isAllureMetaCleanUp = TEST_NAME_AUTO_CLEAN_UP.prop(true)

private val isStepShouldThrowSupportEnabled = STEP_SHOULD_THROW_SUPPORT.prop(true)

internal inline fun <reified T> T.toOptional() = Optional.ofNullable(this)

internal fun String.logger() = LoggerFactory.getLogger(this)
Expand Down Expand Up @@ -106,8 +109,9 @@ internal object InternalUtil {
internal fun AllureTestResult.updateStatus(statusAndDetails: Pair<Status, StatusDetails>) {
// Kotest 5.4.X listener doesn't take into account child steps results.
// We should find previous fail / broken child steps in ALLURE storage and use it on top
val closestPreviousErrorOrBrokenStatusAndDetails: Pair<Status, StatusDetails> =
val closestPreviousErrorOrBrokenStatusAndDetails: Pair<Status, StatusDetails> = statusAndDetails.takeIf { isStepShouldThrowSupportEnabled }.let {
steps.map { it.status to it.statusDetails }.lastOrNull { it.first.isBrokenOrFailed } ?: statusAndDetails
}

val effectiveStatusAndDetails =
if (statusAndDetails.first.isNotPassed) statusAndDetails else closestPreviousErrorOrBrokenStatusAndDetails
Expand Down
11 changes: 11 additions & 0 deletions src/test/kotlin/ru/iopump/kotest/allure/ExampleStringSpec.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ru.iopump.kotest.allure

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.data.forAll
import io.kotest.data.row
import io.qameta.allure.Epic
import io.qameta.allure.Feature
import io.qameta.allure.Link
import io.qameta.allure.Links
import io.qameta.allure.Step
import ru.iopump.kotest.allure.api.KotestAllureExecution.setUpFixture
import ru.iopump.kotest.allure.api.KotestAllureExecution.tearDownFixture

Expand All @@ -33,6 +35,15 @@ class ExampleStringSpec : StringSpec() {
}
}

"If step throws exception in shouldThrow block test must not break" {
shouldThrow<Exception> { throwException() }
}

tearDownFixture("Tear Down testing fixture")
}

@Step("Throw exception")
fun throwException() {
throw Exception()
}
}