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

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

enabled.kt

Source:enabled.kt Github

copy

Full Screen

...6import io.kotest.engine.spec.SpecExtensions7import io.kotest.engine.tags.runtimeTags8/**9 * Returns [Enabled.enabled] if the given [TestCase] is enabled based on default rules10 * from [isEnabledInternal] or any registered [EnabledExtension]s.11 */12suspend fun TestCase.isEnabled(conf: ProjectConfiguration): Enabled {13 val internal = isEnabledInternal(conf)14 return if (!internal.isEnabled) {15 internal16 } else {17 val disabled = SpecExtensions(conf.registry)18 .extensions(spec)19 .filterIsInstance<EnabledExtension>()20 .map { it.isEnabled(descriptor) }21 .firstOrNull { it.isDisabled }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

...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

...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

...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

...7/**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

...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

...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.kt

Source:TestEnabledExtension.kt Github

copy

Full Screen

...7 * Any extension can choose to disable a test - all extensions must reply enabled8 * for a test to be considered active.9 */10internal interface TestEnabledExtension {11 fun isEnabled(testCase: TestCase): Enabled12}...

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1+fun testEnabledExtension() {2+ test("this test is enabled") {3+ }.config(enabled = false)4+}5+fun testDisabledExtension() {6+ test("this test is disabled") {7+ }.config(enabled = false)8+}9+fun testIgnoredExtension() {10+ test("this test is ignored") {11+ }.config(enabled = false)12+}13+fun testInstancePerTestExtension() {14+ test("this test is instance per test") {15+ }.config(enabled = false)16+}17+fun testInstancePerLeafExtension() {18+ test("this test is instance per leaf") {19+ }.config(enabled = false)20+}21+fun testInstancePerNodeExtension() {22+ test("this test is instance per node") {23+ }.config(enabled = false)24+}25+fun testInstancePerSpecExtension() {26+ test("this test is instance per spec") {27+ }.config(enabled = false)28+}29+fun testParallelizableExtension() {30+ test("this test is parallelizable") {31+ }.config(enabled = false)32+}33+fun testNotParallelizableExtension() {34+ test("this test is not parallel

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1+ val testEnabledExtension = TestEnabledExtension()2+ val enabled = testEnabledExtension.isEnabled(context)3+ if (!enabled) {4+ }5 if (context is SpecRootTest || context is ContainerTest) {6@@ -73,6 +88,7 @@ class TestExecutor(7 private suspend fun executeTest(8 ): TestResult {9@@ -80,7 +96,7 @@ class TestExecutor(10- val enabled = isEnabled(context)11 val result = if (enabled) {12 val testCase = TestCase(13@@ -109,7 +125,7 @@ class TestExecutor(14 } else {15 }16- lifecycle.afterTest(context, result)17+ lifecycle.afterTest(context, result, enabled)18 }19@@ -120,7 +136,7 @@ class TestExecutor(20 private fun executeTestWithTimeout(21 ): TestResult {22@@ -130,7 +146,7 @@ class TestExecutor(23- val enabled = isEnabled(context)24 val result = if (enabled) {25 val testContext = TestContext(26@@ -158,7 +174,7 @@ class TestExecutor(27 } else {28 }29- lifecycle.afterTest(context, result)30+ lifecycle.afterTest(context, result, enabled)31 }32@@ -169,7 +185,7 @@ class TestExecutor(

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1fun testEnabledExtension() {2 val spec = object : FunSpec({3 test("some test").config(enabled = false) {4 }5 }) {}.spec6 val test = spec.testCases().first()7 println(test.isEnabled())8}

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1+ fun `test is enabled or disabled`() {2+ val testEnabledExtension = TestEnabledExtension()3+ val testCase = TestCase(4+ TestName("test name"),5+ Descriptor.Test(6+ Descriptor.Spec(Spec::class),7+ TestName("test name"),8+ {},9+ SourceRef(1, 2, 3),10+ InvocationCount(1),11+ val enabled = testEnabledExtension.isEnabled(testCase)12+ println(enabled)

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1 "Test case 2" {2 val result = isEnabled("Test case 1")3 println(result)4 }5 }6})

Full Screen

Full Screen

isEnabled

Using AI Code Generation

copy

Full Screen

1fun main() {2 fun isTestEnabled(test: TestCase): Boolean {3 val status = test.description.testCaseExtension(TestEnabledExtension).status4 }5 val spec = object : FunSpec() {6 init {7 test("a test").config(enabled = false) {8 }9 test("b test") {10 }11 }12 }13 val listener = object : TestEngineListener {14 override fun engineFinished(t: List<Throwable>) {}15 override fun engineStarted(classes: List<KClass<out Spec>>) {}16 override fun specFinished(kclass: KClass<out Spec>, t: Throwable?) {}17 override fun specStarted(kclass: KClass<out Spec>) {}18 override fun testFinished(testCase: TestCase, result: TestResult) {19 val enabled = isTestEnabled(testCase)20 println("${testCase.description.testPath().value} is enabled? $enabled")21 }22 override fun testIgnored(testCase: TestCase, reason: String?) {}23 override fun testStarted(testCase: TestCase) {}24 }25 TestEngineLauncher(listener).withClasses(spec::class).launch()26}

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 method 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