How to use create method of org.spekframework.spek2.runtime.JvmDiscoveryContextFactory class

Best Spek code snippet using org.spekframework.spek2.runtime.JvmDiscoveryContextFactory.create

SpekTestEngine.kt

Source:SpekTestEngine.kt Github

copy

Full Screen

...72 // todo: empty filter should imply root73 if (filters.isEmpty()) {74 filters.add(PathBuilder.ROOT)75 }76 val context = JvmDiscoveryContextFactory.create(sourceDirs)77 val discoveryResult = runtime.discover(DiscoveryRequest(context, filters.toList()))78 discoveryResult.roots79 .map { descriptorFactory.create(it) }80 .forEach(engineDescriptor::addChild)81 return engineDescriptor82 }83 override fun execute(request: JUnitExecutionRequest) {84 val roots = request.rootTestDescriptor.children85 .filterIsInstance<SpekTestDescriptor>()86 .map(SpekTestDescriptor::scope)87 val executionRequest = ExecutionRequest(88 roots, JUnitEngineExecutionListenerAdapter(request.engineExecutionListener, descriptorFactory)89 )90 runtime.execute(executionRequest)91 }92 private fun containsUnsupportedSelector(discoveryRequest: EngineDiscoveryRequest): Boolean {93 for (selector in UNSUPPORTED_SELECTORS) {...

Full Screen

Full Screen

JvmDiscoveryContextFactory.kt

Source:JvmDiscoveryContextFactory.kt Github

copy

Full Screen

...10import kotlin.reflect.full.primaryConstructor11import kotlin.streams.toList12object JvmDiscoveryContextFactory {13 private val defaultInstanceFactory = object : InstanceFactory {14 override fun <T : Spek> create(spek: KClass<T>): T {15 return spek.objectInstance ?: spek.constructors.first { it.parameters.isEmpty() }16 .call()17 }18 }19 fun create(testDirs: List<String>): DiscoveryContext {20 val classes = scanClasses(testDirs)21 val builder = DiscoveryContext.builder()22 classes.filter { !it.isAbstract }23 .filter { it.findAnnotation<Ignore>() == null }24 .map { cls ->25 val instanceFactory = instanceFactoryFor(cls)26 cls to { instanceFactory.create(cls) }27 }.forEach { (cls, factory) ->28 builder.addTest(cls, factory)29 }30 return builder.build()31 }32 private fun instanceFactoryFor(spek: KClass<*>): InstanceFactory {33 return spek.annotations.filterIsInstance<CreateWith>()34 .map { it.factory }35 .map { it.objectInstance ?: it.primaryConstructor!!.call() }36 .firstOrNull() ?: defaultInstanceFactory37 }38 private fun scanClasses(testDirs: List<String>): List<KClass<out Spek>> {39 val cg = ClassGraph()40 .enableClassInfo()...

Full Screen

Full Screen

console.kt

Source:console.kt Github

copy

Full Screen

...11 val paths = args.paths.map {12 PathBuilder.parse(it)13 .build()14 }15 val context = JvmDiscoveryContextFactory.create(args.sourceDirs.toList())16 val discoveryRequest = DiscoveryRequest(context, paths)17 val runtime = SpekRuntime()18 val discoveryResult = runtime.discover(discoveryRequest)19 val executionRequest = ExecutionRequest(discoveryResult.roots, ServiceMessageAdapter())20 runtime.execute(executionRequest)21 }22}23class LauncherArgs(parser: ArgParser) {24 val sourceDirs by parser.adding("--sourceDirs", help="Spec source dirs")25 val paths by parser.adding("--paths", help = "Spek paths to execute")26}27fun main(args: Array<String>) = mainBody {28 val launcherArgs = ArgParser(args).parseInto(::LauncherArgs)29 Spek2ConsoleLauncher().run(launcherArgs)...

Full Screen

Full Screen

DiscoveryRequest.kt

Source:DiscoveryRequest.kt Github

copy

Full Screen

...4import org.spekframework.spek2.runtime.scope.Path5actual class DiscoveryRequest actual constructor(actual val context: DiscoveryContext,6 actual val paths: List<Path>) {7 // TODO: remove on the next release after 2.0.1, it's only here for compatibility8 constructor(testDirs: List<String>, paths: List<Path>): this(JvmDiscoveryContextFactory.create(testDirs), paths)9}...

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()2val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()3val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()4val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()5val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()6val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()7val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()8val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()9val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()10val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()11val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()12val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()13val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()14val discoveryContext = JvmDiscoveryContextFactory.createDiscoveryContext()

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory.create(discoveryContextFactory, path)2val executionRequest = JvmExecutionRequestFactory.create(discoveryContext, executionContextFactory)3SpekRuntime.execute(executionRequest)4SpekRuntime.execute(executionRequest, executionListener)5SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor)6SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor)7SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor)8SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor)9SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor)10SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor)11SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor)12SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor, executionResultProcessor)13SpekRuntime.execute(executionRequest, executionListener, executionResultProcessor, executionResultProcessor,

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory.create(classLoader, paths)2val discoveryRequest = JvmDiscoveryRequest(discoveryContext, paths)3val discoveryResult = JvmDiscovery(discoveryRequest).discover()4val executionRequest = JvmExecutionRequest(discoveryResult, listener, paths)5val executionResult = JvmTestEngine().execute(executionRequest)6return TestResult(executionResult)7}8}9}10import org.spekframework.spek2.runtime.SpekRuntime11import org.spekframework.spek2.runtime.execution.ExecutionListener12import org.spekframework.spek2.runtime.execution.ExecutionResult13import org.spekframework.spek2.runtime.execution.ExecutionStart14import org.spekframework.spek2.runtime.execution.ExecutionStop15import org.spekframework.spek2.runtime.scope.Path16class MyTestEngine: TestEngine {17override fun execute(paths: List<Path>, listener: ExecutionListener): ExecutionResult {18val runtime = SpekRuntime()19val result = runtime.execute(paths, listener)20return ExecutionResult(result)21}22override fun discover(paths: List<Path>, listener: ExecutionListener) {23val runtime = SpekRuntime()24runtime.discover(paths, listener)25}26}27val engine = MyTestEngine()28val paths = listOf(Path.parse("org.example.MySpek"))29engine.discover(paths, object: ExecutionListener {30override fun executionStart(request: ExecutionStart) {31println("Test discovery started")32}33override fun executionStop(request: ExecutionStop) {34println("Test discovery finished")35}36})37val result = engine.execute(paths, object: ExecutionListener {38override fun executionStart(request: ExecutionStart) {39println("Test execution started")40}41override fun executionStop(request: ExecutionStop) {42println("Test execution finished")43}44})45println(result)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory.create(discoveryRequest)2val executionContext = JvmExecutionContextFactory.createExecutionContext(discoveryContext)3val runtime = SpekRuntime()4val listener = MyTestListener()5runtime.execute(discoveryContext, executionContext, listener)6}7}8class MyTestListener : TestListener {9override fun testFinished(testResult: TestResult) {10println("Test finished: ${testResult.testCase.displayName} - ${testResult.status}")11}12override fun testStarted(testCase: TestCase) {13println("Test started: ${testCase.displayName}")14}15}

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1import org.spekframework.spek2.runtime.JvmDiscoveryContextFactory2import org.spekframework.spek2.runtime.SpekRuntime3import org.spekframework.spek2.runtime.execution.ExecutionListener4import org.spekframework.spek2.runtime.scope.Path5import org.spekframework.spek2.runtime.scope.TestScopeImpl6val discoveryContext = JvmDiscoveryContextFactory().create(object : ExecutionListener {7 override fun executionStart() {8 }9 override fun executionFinish() {10 }11 override fun testExecutionStart(test: TestScopeImpl) {12 }13 override fun testExecutionFinish(test: TestScopeImpl, result: TestResult) {14 }15 override fun testIgnored(test: TestScopeImpl, reason: String?) {16 }17 override fun groupExecutionStart(group: GroupScopeImpl) {18 }19 override fun groupExecutionFinish(group: GroupScopeImpl, result: TestResult) {20 }21 override fun groupIgnored(group: GroupScopeImpl, reason: String?) {22 }23}, discoveryRequest)24SpekRuntime().execute(discoveryContext)

Full Screen

Full Screen

create

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory().create(DiscoveryRequest())2val specs = discoveryContext.discover()3val engine = JvmEngine()4val results = engine.execute(specs)5val reporter = TextReporter()6reporter.report(results)7val xmlReporter = XmlReporter()8xmlReporter.report(results)9val jsonReporter = JsonReporter()10jsonReporter.report(results)11val junitXmlReporter = JUnitXmlReporter()12junitXmlReporter.report(results)13val junitHtmlReporter = JUnitHtmlReporter()14junitHtmlReporter.report(results)15val junitConsoleReporter = JUnitConsoleReporter()16junitConsoleReporter.report(results)

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 Spek automation tests on LambdaTest cloud grid

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

Most used method in JvmDiscoveryContextFactory

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful