How to use JvmDiscoveryContextFactory class of org.spekframework.spek2.runtime package

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

SpekTestEngine.kt

Source:SpekTestEngine.kt Github

copy

Full Screen

...3import org.junit.platform.engine.TestDescriptor4import org.junit.platform.engine.TestEngine5import org.junit.platform.engine.UniqueId6import org.junit.platform.engine.discovery.*7import org.spekframework.spek2.runtime.JvmDiscoveryContextFactory8import org.spekframework.spek2.runtime.SpekRuntime9import org.spekframework.spek2.runtime.execution.DiscoveryRequest10import org.spekframework.spek2.runtime.execution.ExecutionRequest11import org.spekframework.spek2.runtime.scope.Path12import org.spekframework.spek2.runtime.scope.PathBuilder13import java.lang.reflect.Modifier14import java.nio.file.Paths15import org.junit.platform.engine.ExecutionRequest as JUnitExecutionRequest16class SpekTestEngine : TestEngine {17 companion object {18 const val ID = "spek2"19 // Spek does not know how to handle these selectors, fallback to no matching tests.20 private val UNSUPPORTED_SELECTORS = listOf(21 MethodSelector::class.java,22 FileSelector::class.java,23 ModuleSelector::class.java,24 ClasspathResourceSelector::class.java,25 UniqueIdSelector::class.java,26 UriSelector::class.java,27 DirectorySelector::class.java28 )29 }30 private val descriptorFactory = SpekTestDescriptorFactory()31 private val runtime by lazy { SpekRuntime() }32 override fun getId() = ID33 override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor {34 val engineDescriptor = SpekEngineDescriptor(uniqueId, id)35 if (containsUnsupportedSelector(discoveryRequest)) {36 return engineDescriptor37 }38 val sourceDirs = discoveryRequest.getSelectorsByType(ClasspathRootSelector::class.java)39 .map { it.classpathRoot }40 .map { Paths.get(it) }41 .map { it.toString() }42 val classSelectors = discoveryRequest.getSelectorsByType(ClassSelector::class.java)43 .filter {44 // get all super classes45 val superClasses = mutableListOf<String>()46 var current = it.javaClass.superclass47 while (current != null) {48 superClasses.add(current.name)49 current = current.superclass50 }51 superClasses.contains("org.spekframework.spek2.Spek")52 }53 .filter {54 !(it.javaClass.isAnonymousClass55 || it.javaClass.isLocalClass56 || it.javaClass.isSynthetic57 || Modifier.isAbstract(it.javaClass.modifiers))58 }.map {59 PathBuilder60 .from(it.javaClass.kotlin)61 .build()62 }63 val packageSelectors = discoveryRequest.getSelectorsByType(PackageSelector::class.java)64 .map {65 PathBuilder()66 .appendPackage(it.packageName)67 .build()68 }69 val filters = linkedSetOf<Path>()70 filters.addAll(classSelectors)71 filters.addAll(packageSelectors)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)...

Full Screen

Full Screen

JvmDiscoveryContextFactory.kt

Source:JvmDiscoveryContextFactory.kt Github

copy

Full Screen

...8import kotlin.reflect.KClass9import kotlin.reflect.full.findAnnotation10import 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) }...

Full Screen

Full Screen

console.kt

Source:console.kt Github

copy

Full Screen

1package org.spekframework.ide2import com.xenomachina.argparser.ArgParser3import com.xenomachina.argparser.mainBody4import org.spekframework.spek2.runtime.JvmDiscoveryContextFactory5import org.spekframework.spek2.runtime.SpekRuntime6import org.spekframework.spek2.runtime.execution.DiscoveryRequest7import org.spekframework.spek2.runtime.execution.ExecutionRequest8import org.spekframework.spek2.runtime.scope.PathBuilder9class Spek2ConsoleLauncher {10 fun run(args: LauncherArgs) {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

1package org.spekframework.spek2.runtime.execution2import org.spekframework.spek2.runtime.JvmDiscoveryContextFactory3import org.spekframework.spek2.runtime.discovery.DiscoveryContext4import 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

JvmDiscoveryContextFactory

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory().create()2val discoveryRequest = JvmDiscoveryRequestFactory().create()3val discoveryContext = JvmDiscoveryContextFactory().create()4val discoveryRequest = JvmDiscoveryRequestFactory().create()5val discoveryContext = JvmDiscoveryContextFactory().create()6val discoveryRequest = JvmDiscoveryRequestFactory().create()

Full Screen

Full Screen

JvmDiscoveryContextFactory

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory().createDiscoveryContext()2val discoveryRequest = JvmDiscoveryRequestFactory().createDiscoveryRequest(discoveryContext, classpath)3val discoveryResult = JvmDiscoveryRequestFactory().createDiscoveryResult(discoveryRequest)4val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()5val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()6val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()7val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()8val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()9val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()10val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()11val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()12val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()13val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelectorResolver()14val discoverySelectorResolver = JvmDiscoveryRequestFactory().createDiscoverySelector

Full Screen

Full Screen

JvmDiscoveryContextFactory

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory().create()2val discoveryRequest = JvmDiscoveryRequestFactory().create()3val discoveryContext = JvmDiscoveryContextFactory().create()4val discoveryRequest = JvmDiscoveryRequestFactory().create()5val discoveryContext = JvmDiscoveryContextFactory().create()6val discoveryRequest = JvmDiscoveryRequestFactory().create()

Full Screen

Full Screen

JvmDiscoveryContextFactory

Using AI Code Generation

copy

Full Screen

1val jvmDiscoveryContextFactory = JvmDiscoveryContextFactory()2val discoveryContext = jvmDiscoveryContextFactory.create()3val discovery = JvmDiscovery(discoveryContext)4val discoveryResult = discovery.discover()5val jvmDiscoveryResultProcessor = JvmDiscoveryResultProcessor()6val executionRequest = jvmDiscoveryResultProcessor.process(discoveryResult)7val jvmExecutionRequest = JvmExecutionRequest()8val executionResult = jvmExecutionRequest.execute(executionRequest)9val jvmExecutionResultProcessor = JvmExecutionResultProcessor()10val executionSummary = jvmExecutionResultProcessor.process(executionResult)11val jvmExecutionSummary = JvmExecutionSummary()12val summary = jvmExecutionSummary.process(executionSummary)13val jvmExecutionSummaryProcessor = JvmExecutionSummaryProcessor()14val summaryResult = jvmExecutionSummaryProcessor.process(summary)15val jvmExecutionResult = JvmExecutionResult()16val result = jvmExecutionResult.process(executionResult)17val jvmTestEngine = JvmTestEngine()18val testEngine = jvmTestEngine.process()19val jvmTestEngineDiscoveryRequest = JvmTestEngineDiscoveryRequest()20val testEngineDiscoveryRequest = jvmTestEngineDiscoveryRequest.process()21val jvmTestEngineExecutionRequest = JvmTestEngineExecutionRequest()22val testEngineExecutionRequest = jvmTestEngineExecutionRequest.process()23val jvmTestEngineExecutionResult = JvmTestEngineExecutionResult()

Full Screen

Full Screen

JvmDiscoveryContextFactory

Using AI Code Generation

copy

Full Screen

1val discoveryContextFactory = JvmDiscoveryContextFactory()2val discoveryContext = discoveryContextFactory.createDiscoveryContext()3val discoveryRequest = discoveryContext.createDiscoveryRequest()4discoveryRequest.discover(discoveryContext)5val discoveryResult = discoveryContext.getDiscoveryResult()6discoveryResult.getGroups().forEach { group ->7println(group.name)8}9}10}

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