All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.JvmTestExecutor.kt Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
package opensavvy.prepared.runner.kotlin

import opensavvy.prepared.suite.SuiteDsl
import opensavvy.prepared.suite.TestDsl
import opensavvy.prepared.suite.config.Ignored
import opensavvy.prepared.suite.config.TestConfig
import opensavvy.prepared.suite.config.get
import opensavvy.prepared.suite.config.plus
import opensavvy.prepared.suite.runTestDsl
import org.junit.jupiter.api.*
import java.util.stream.Stream
import kotlin.coroutines.CoroutineContext

actual abstract class TestExecutor {

	actual open val config: TestConfig
		get() = TestConfig.Empty

	actual abstract fun SuiteDsl.register()

	@TestFactory
	fun suite(): Stream {
		val suite = JvmSuiteDsl(config).apply { register() }

		return suite.nodes.stream()
	}

}

private class JvmSuiteDsl(val parentConfig: TestConfig) : SuiteDsl {
	val nodes = ArrayList()

	override fun suite(name: String, config: TestConfig, block: SuiteDsl.() -> Unit) {
		val child = JvmSuiteDsl(parentConfig + config).apply(block)

		nodes += DynamicContainer.dynamicContainer(name, child.nodes)
	}

	override fun test(name: String, context: CoroutineContext, config: TestConfig, block: suspend TestDsl.() -> Unit) {
		val thisConfig = parentConfig + config
		nodes += DynamicTest.dynamicTest(name) {
			// Immediately fail the test if it is marked as disabled
			Assumptions.assumeTrue(thisConfig[Ignored] == null)

			runTestDsl(name, context, thisConfig, block)
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy