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

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

JvmDiscoveryContextFactory.kt

Source:JvmDiscoveryContextFactory.kt Github

copy

Full Screen

...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()41 if (testDirs.isNotEmpty()) {42 cg.overrideClasspath(System.getProperty("java.class.path"), testDirs)43 }44 return cg.scan().use {45 it.getSubclasses(Spek::class.qualifiedName!!).stream()46 .map { it.loadClass() as Class<out Spek> }47 .filter { !it.isAnonymousClass }48 .map { it.kotlin }49 .toList()50 }51 }52}...

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1import org.spekframework.spek2.runtime.JvmDiscoveryContextFactory import org.spekframework.spek2.runtime.discovery.DiscoveryContext2val discoveryContext = JvmDiscoveryContextFactory().createDiscoveryContext() val testClasses = discoveryContext.scanClasses()3import org.spekframework.spek2.runtime.SpekRuntime4val runtime = SpekRuntime()5import org.spekframework.spek2.runtime.SpekRuntime6val runtime = SpekRuntime() val listener = MyTestListener() runtime.run(testClasses, listener)7plugins { id 'org.spekframework.spek2' version '2.0.8' }

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1val discoveryContext = JvmDiscoveryContextFactory.scanClasses(listOf(YourSpec::class.java))2val discoveryContext = JvmDiscoveryContextFactory.scanClasspath()3val discoveryContext = JvmDiscoveryContextFactory.scanPackage(“com.your.package”)4val executionContext = JvmExecutionContextFactory.create()5val listener = MyListener()6val runner = JvmTestRunner()7runner.execute(discoveryContext, executionContext, listener)

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1 val discoveryContext = JvmDiscoveryContextFactory().create()2 val classpathRoots = listOf(Paths.get("build/classes/kotlin/main"))3 val classes = discoveryContext.scanClasses(classpathRoots)4 val classesNames = classes.map { it.javaClass.name }5 println(classesNames)6 val discoveryContext = JvmDiscoveryContextFactory().create()7 val classpathRoots = listOf(Paths.get("build/classes/kotlin/test"))8 val classes = discoveryContext.scanClasses(classpathRoots)9 val classesNames = classes.map { it.javaClass.name }10 println(classesNames)11 val discoveryContext = JvmDiscoveryContextFactory().create()12 val classpathRoots = listOf(Paths.get("build/classes/kotlin/jvmTest"))13 val classes = discoveryContext.scanClasses(classpathRoots)14 val classesNames = classes.map { it.javaClass.name }15 println(classesNames)16 val discoveryContext = JvmDiscoveryContextFactory().create()17 val classpathRoots = listOf(Paths.get("build/classes/kotlin/jvmMain"))18 val classes = discoveryContext.scanClasses(classpathRoots)19 val classesNames = classes.map { it.javaClass.name }20 println(classesNames)

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1val spekClasses = JvmDiscoveryContextFactory.scanClasses("com.example")2val spekTestDescriptors = spekClasses.map { SpekTestDescriptor(it) }3val spekTestEngine = SpekTestEngine()4spekTestEngine.execute(spekTestDescriptors)5val spekTestEngine = SpekTestEngine()6val spekTestPlan = SpekTestPlan()7val spekTestExecutor = SpekTestExecutor()8spekTestExecutor.execute(spekTestEngine, spekTestPlan)

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1val testClasses = JvmDiscoveryContextFactory.scanClasses(listOf("com.example"))2val testClasses = JvmDiscoveryContextFactory.scanClasses(listOf("com.example"))3val relatedTests = testClasses.flatMap { testClass ->4testClass.tests.filter { test ->5}6}

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1test {2}3test {4}5test {6}

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1val spekClasses = JvmDiscoveryContextFactory.scanClasses("com.example")2val spekTestDescriptors = spekClasses.map { SpekTestDescriptor(it) }3val spekTestEngine = SpekTestEngine()4spekTestEngine.execute(spekTestDescriptors)5val spekTestEngine = SpekTestEngine()6val spekTestPlan = SpekTestPlan()7val spekTestExecutor = SpekTestExecutor()8spekTestExecutor.execute(spekTestEngine, spekTestPlan)

Full Screen

Full Screen

scanClasses

Using AI Code Generation

copy

Full Screen

1val testClasses = JvmDiscoveryContextFactory.scanClasses(listOf("com.example"))2val testClasses = JvmDiscoveryContextFactory.scanClasses(listOf("com.example"))3val relatedTests = testClasses.flatMap { testClass ->4testClass.tests.filter { test ->5}6}

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