How to use TestEnabledExtension class of io.kotest.engine.test.status package

Best Kotest code snippet using io.kotest.engine.test.status.TestEnabledExtension

SystemPropertyTestFilterEnabledExtension.kt

Source:SystemPropertyTestFilterEnabledExtension.kt Github

copy

Full Screen

...13 *14 * These work similarly to gradle filters in --tests described at:15 * https://docs.gradle.org/current/userguide/java_testing.html#full_qualified_name_pattern16 */17internal object SystemPropertyTestFilterEnabledExtension : TestEnabledExtension {18 private val logger = Logger(SystemPropertyTestFilterEnabledExtension::class)19 override fun isEnabled(testCase: TestCase): Enabled {20 val filter = syspropOrEnv(KotestEngineProperties.filterTests) ?: ""21 logger.log { Pair(testCase.name.testName, "Filter tests syspropOrEnv=$filter") }22 val excluded = filter23 .propertyToRegexes()24 .map { it.toTestFilter().filter(testCase.descriptor) }25 .filterIsInstance<TestFilterResult.Exclude>()26 .firstOrNull()27 logger.log { Pair(testCase.name.testName, "excluded = $excluded") }28 return if (excluded == null) Enabled.enabled else Enabled.disabled(excluded.reason)29 }30}31private fun Regex.toTestFilter(): TestFilter = object : TestFilter {...

Full Screen

Full Screen

enabled.kt

Source:enabled.kt Github

copy

Full Screen

...22 disabled ?: Enabled.enabled23 }24}25/**26 * Determines enabled status by using [TestEnabledExtension]s.27 */28internal fun TestCase.isEnabledInternal(conf: ProjectConfiguration): Enabled {29 val extensions = listOf(30 TestConfigEnabledExtension,31 TagsEnabledExtension(conf.runtimeTags()),32 TestFilterEnabledExtension(conf.registry),33 SystemPropertyTestFilterEnabledExtension,34 FocusEnabledExtension,35 BangTestEnabledExtension,36 SeverityLevelEnabledExtension,37 )38 return extensions.fold(Enabled.enabled) { acc, ext -> if (acc.isEnabled) ext.isEnabled(this) else acc }39}...

Full Screen

Full Screen

SeverityLevelEnabledExtension.kt

Source:SeverityLevelEnabledExtension.kt Github

copy

Full Screen

...5import io.kotest.core.test.TestCaseSeverityLevel6import io.kotest.mpp.log7import io.kotest.mpp.sysprop8/**9 * This [TestEnabledExtension] disables tests if a test's [TestCaseSeverityLevel] is lower than10 * the runtime minimum severity level.11 *12 * If a test case does not specify a level, then it defaults to [TestCaseSeverityLevel.NORMAL].13 *14 * Note: If no minimum severity level is specified, then this extension has no effect.15 */16internal object SeverityLevelEnabledExtension : TestEnabledExtension {17 override fun isEnabled(testCase: TestCase): Enabled {18 // if min level is not defined, then we always allow through19 val minLevel = sysprop(KotestEngineProperties.testSeverity)20 ?.let { TestCaseSeverityLevel.valueOf(it) }21 ?: return Enabled.enabled22 val testLevel = testCase.config.severity23 return when {24 testLevel.level >= minLevel.level -> Enabled.enabled25 else -> Enabled26 .disabled("${testCase.descriptor.path()} is disabled by severityLevel")27 .also { it.reason?.let { log { it } } }28 }29 }30}...

Full Screen

Full Screen

TagsEnabledExtension.kt

Source:TagsEnabledExtension.kt Github

copy

Full Screen

...5import io.kotest.engine.tags.isActive6import io.kotest.engine.tags.parse7import io.kotest.mpp.log8/**9 * A [TestEnabledExtension] that uses [io.kotest.core.Tag]s.10 *11 * This extension disables a test if:12 *13 * - Excluded tags have been specified and this test has a [io.kotest.core.Tag] which is one of those excluded.14 * - Included tags have been specified and this test either has no tags,15 * or does not have any of the specified inclusion tags.16 *17 * Note: tags are attached to tests either through test config, or at the spec level.18 */19internal class TagsEnabledExtension(private val tags: TagExpression) : TestEnabledExtension {20 override fun isEnabled(testCase: TestCase): Enabled {21 val enabledInTags = tags.parse().isActive(testCase.config.tags)22 if (!enabledInTags) {23 return Enabled24 .disabled("Disabled by tags: ${tags.expression}")25 .also { it.reason?.let { log { it } } }26 }27 return Enabled.enabled28 }29}...

Full Screen

Full Screen

FocusEnabledExtension.kt

Source:FocusEnabledExtension.kt Github

copy

Full Screen

...3import io.kotest.core.test.TestCase4import io.kotest.core.test.isRootTest5import io.kotest.mpp.log6/**7 * This [TestEnabledExtension] disables tests if the containing spec has focused tests,8 * and this test is not focused.9 *10 * Note: This extension only applies to root tests.11 * Nested tests are not affected by this extension.12 */13internal object FocusEnabledExtension : TestEnabledExtension {14 override fun isEnabled(testCase: TestCase): Enabled {15 // focus only applies to root tests16 if (!testCase.isRootTest()) return Enabled.enabled17 // if we are focused doesn't matter what anyone else does18 if (testCase.name.focus) return Enabled.enabled19 // if anything else is focused we're outta luck20 if (testCase.spec.rootTests().any { it.name.focus }) {21 return Enabled22 .disabled("${testCase.descriptor.path().value} is disabled by another test having focus")23 .also { it.reason?.let { log { it } } }24 }25 return Enabled.enabled26 }27}...

Full Screen

Full Screen

TestFilterEnabledExtension.kt

Source:TestFilterEnabledExtension.kt Github

copy

Full Screen

...4import io.kotest.core.filter.TestFilterResult5import io.kotest.core.test.Enabled6import io.kotest.core.test.TestCase7/**8 * This [TestEnabledExtension] disables tests if they are filtered by a [TestFilter].9 */10internal class TestFilterEnabledExtension(private val registry: ExtensionRegistry) : TestEnabledExtension {11 override fun isEnabled(testCase: TestCase): Enabled {12 val filters = registry.all().filterIsInstance<TestFilter>()13 val excluded = filters14 .map { it.filter(testCase.descriptor) }15 .filterIsInstance<TestFilterResult.Exclude>()16 .firstOrNull()17 return when {18 excluded == null -> Enabled.enabled19 excluded.reason == null -> Enabled.disabled("${testCase.descriptor.path(false).value} is excluded by test filter(s)")20 else -> Enabled.disabled("${testCase.descriptor.path(false).value} is excluded by test filter(s): ${excluded.reason}")21 }22 }23}...

Full Screen

Full Screen

BangTestEnabledExtension.kt

Source:BangTestEnabledExtension.kt Github

copy

Full Screen

...4import io.kotest.core.test.TestCase5import io.kotest.mpp.log6import io.kotest.mpp.sysprop7/**8 * A [TestEnabledExtension] that disabled a test if the name of the test is prefixed with "!"9 * and System.getProperty("kotest.bang.disable") has a null value (ie, not defined)10 */11internal object BangTestEnabledExtension : TestEnabledExtension {12 override fun isEnabled(testCase: TestCase): Enabled {13 // this sys property disables the use of !14 // when it is true, we don't check for !15 if (sysprop(KotestEngineProperties.disableBangPrefix) == "true") {16 return Enabled.enabled17 }18 if (testCase.name.bang) {19 return Enabled20 .disabled("Disabled by bang")21 .also { it.reason?.let { log { it } } }22 }23 return Enabled.enabled24 }25}...

Full Screen

Full Screen

TestConfigEnabledExtension.kt

Source:TestConfigEnabledExtension.kt Github

copy

Full Screen

2import io.kotest.core.test.Enabled3import io.kotest.core.test.TestCase4import io.kotest.mpp.log5/**6 * A [TestEnabledExtension] that uses the enabled value in test case config7 * to determine if a test is enabled.8 */9internal object TestConfigEnabledExtension : TestEnabledExtension {10 override fun isEnabled(testCase: TestCase): Enabled {11 val enabled = testCase.config.enabled(testCase)12 if (enabled.isDisabled)13 log { "${testCase.descriptor.path()} is disabled by enabledOrReasonIf function in config: ${enabled.reason}" }14 return enabled15 }16}...

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+import io.kotest.core.config.AbstractProjectConfig2+import io.kotest.core.extensions.Extension3+import io.kotest.core.spec.Spec4+import io.kotest.engine.test.status.TestEnabledExtension5+class ProjectConfig : AbstractProjectConfig() {6+ override fun extensions(): List<Extension> = listOf(TestEnabledExtension())7+}8+import io.kotest.core.config.AbstractProjectConfig9+import io.kotest.core.extensions.Extension10+import io.kotest.core.spec.Spec11+import io.kotest.engine.test.status.TestDisabledExtension12+class ProjectConfig : AbstractProjectConfig() {13+ override fun extensions(): List<Extension> = listOf(TestDisabledExtension())14+}15+import io.kotest.core.config.AbstractProjectConfig16+import io.kotest.core.extensions.Extension17+import io.kotest.core.spec.Spec18+import io.kotest.engine.test.status.TestIgnoredExtension19+class ProjectConfig : AbstractProjectConfig() {20+ override fun extensions(): List<Extension> = listOf(TestIgnoredExtension())21+}

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+val TestStatus.isTestEnabled: Boolean get() = this is TestEnabled2+val TestStatus.isTestDisabled: Boolean get() = this is TestDisabled3+val TestStatus.isTestIgnored: Boolean get() = this is TestIgnored4+val TestStatus.isTestError: Boolean get() = this is TestError5+val TestStatus.isTestStatus: Boolean get() = this is TestStatus6+val TestStatus.isTestResult: Boolean get() = this is TestResult7+val TestStatus.isTestSuccess: Boolean get() = this is TestSuccess8+val TestStatus.isTestFailure: Boolean get() = this is TestFailure9+val TestStatus.isTestIgnored: Boolean get() = this is TestIgnored10+val TestStatus.isTestError: Boolean get() = this is TestError11+val TestStatus.isTestStatus: Boolean get() = this is TestStatus12+val TestStatus.isTestResult: Boolean get() = this is TestResult13+val TestStatus.isTestSuccess: Boolean get() = this is TestSuccess14+val TestStatus.isTestFailure: Boolean get() = this is TestFailure

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+class TestEnabledExtension : Extension {2+ override fun intercept(3+ process: (ExtensionContext) -> Unit4+ ) {5+ if (status is TestEnabledExtensionStatus) {6+ if (status.enabled) {7+ process(context)8+ } else {9+ }10+ } else {11+ process(context)12+ }13+ }14+}15+class TestEnabledExtensionStatus(val enabled: Boolean) : TestCaseExtensionStatus16+class TestEnabledExtensionFactory : ExtensionFactory {17+ override fun create(18+ ): Extension {19+ return TestEnabledExtension()20+ }21+}22+class MySpec : FunSpec() {23+ init {24+ test("test 1").config(enabled = false) {25+ }26+ test("test 2").config(enabled = true) {27+ }28+ test("test 3") {29+ }30+ }31+}32+class TestStatusExtension : Extension {33+ override fun intercept(34+ process: (ExtensionContext) -> Unit35+ ) {36+ try {37+ process(context)

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+val TestEnabledExtension = TestStatusExtension("TestEnabledExtension") { testEnabled() }2+val TestIgnoredExtension = TestStatusExtension("TestIgnoredExtension") { testIgnored() }3+val TestDisabledExtension = TestStatusExtension("TestDisabledExtension") { testDisabled() }4+val TestErrorExtension = TestStatusExtension("TestErrorExtension") { testError() }5+val TestFailedExtension = TestStatusExtension("TestFailedExtension") { testFailed() }6+val TestFinishedExtension = TestStatusExtension("TestFinishedExtension") { testFinished() }7+val TestStartedExtension = TestStatusExtension("TestStartedExtension") { testStarted() }8+val TestStatusExtension = TestStatusExtension("TestStatusExtension") { testStatus() }9+val TestSuccessExtension = TestStatusExtension("TestSuccessExtension") { testSuccess() }10+val TestTimeoutExtension = TestStatusExtension("TestTimeoutExtension") { testTimeout() }11+val TestIgnoredExtension = TestStatusExtension("TestIgnoredExtension") { testIgnored() }

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+val TestStatus.testEnabledExtension: TestEnabledExtension? get() = extensions[TestEnabledExtension::class]2+val TestStatus.testDisabledExtension: TestDisabledExtension? get() = extensions[TestDisabledExtension::class]3+val TestStatus.testIgnoredExtension: TestIgnoredExtension? get() = extensions[TestIgnoredExtension::class]4+val TestStatus.testErrorExtension: TestErrorExtension? get() = extensions[TestErrorExtension::class]5+val TestStatus.testFailureExtension: TestFailureExtension? get() = extensions[TestFailureExtension::class]6+val TestStatus.testSuccessExtension: TestSuccessExtension? get() = extensions[TestSuccessExtension::class]7+val TestStatus.testFinishedExtension: TestFinishedExtension? get() = extensions[TestFinishedExtension::class]8+val TestStatus.testAbortedExtension: TestAbortedExtension? get() = extensions[TestAbortedExtension::class]9+val TestStatus.testPendingExtension: TestPendingExtension? get() = extensions[TestPendingExtension::class]10+val TestStatus.testSkippedExtension: TestSkippedExtension? get() = extensions[TestSkippedExtension::class]11+val TestStatus.testNotRunExtension: TestNotRunExtension? get() = extensions[TestNotRunExtension::class]12+val TestStatus.testSkippedExtension: TestSkippedExtension? get() = extensions[TestSkippedExtension::class]

Full Screen

Full Screen

TestEnabledExtension

Using AI Code Generation

copy

Full Screen

1+class TestStatusTest : FunSpec({2+ test("test1").config(enabled = false) {3+ println("test1")4+ }5+ test("test2").config(enabledIf = { false }) {6+ println("test2")7+ }8+ test("test3").config(enabledIf = { true }) {9+ println("test3")10+ }11+ test("test4").config(enabledIf = { false }) {12+ println("test4")13+ }14+ test("test5").config(enabled = false) {15+ println("test5")16+ }17+ test("test6").config(enabledIf = { false }) {18+ println("test6")19+ }20+ test("test7").config(enabled = false) {21+ println("test7")22+ }23+ test("test8").config(enabledIf = { false }) {24+ println("test8")25+ }26+ test("test9").config(enabled = false) {27+ println("test9")28+ }29+ test("test10").config(enabledIf = { false }) {30+ println("test10")31+ }32+ test("test11").config(enabled = false) {33+ println("test11")34+ }35+ test("test12").config(enabledIf = { false }) {36+ println("test12")37+ }38+ test("test13").config(enabled = false) {39+ println("test13")40+ }41+ test("test14").config(enabledIf = { false }) {42+ println("test14")43+ }44+ test("test15").config(enabled = false) {45+ println("test15")46+ }47+ test("test16").config(enabledIf = { false }) {48+ println("test16")49+ }50+ test("test17").config(enabled = false) {51+ println("test17")52+ }53+ test("test18").config(enabledIf = { false }) {54+ println("test18")55+ }56+ test("test19").config(enabled = false) {57+ println("test19")58+ }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in TestEnabledExtension

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful