How to use afterEachGroup method of org.spekframework.spek2.runtime.Collector class

Best Spek code snippet using org.spekframework.spek2.runtime.Collector.afterEachGroup


Source:Collectors.kt Github


Full Screen

...31 with(this@Collector) {32 finalizers.add { afterEachTest(fixture) }33 }34 }35 override fun afterEachGroup(fixture: Fixture) {36 with(this@Collector) {37 finalizers.add { afterEachGroup(fixture) }38 }39 }40 override fun afterGroup(fixture: Fixture) {41 with(this@Collector) {42 finalizers.add { afterGroup(fixture) }43 }44 }45 }46 return MemoizedValueCreator(47 root,48 mode,49 lifecycleAware,50 factory,51 destructor52 )53 }54 override fun <T> memoized(): MemoizedValue<T> {55 return MemoizedValueReader(root)56 }57 override fun registerListener(listener: LifecycleListener) {58 lifecycleManager.addListener(listener)59 }60 override fun group(description: String, skip: Skip, defaultCachingMode: CachingMode, preserveExecutionOrder: Boolean, failFast: Boolean, body: GroupBody.() -> Unit) {61 // TODO: combine failFast and preserveExecutionOrder into a single parameter.62 require(failFast == preserveExecutionOrder) { "failFast and preserveExecutionOrder must have the same value!" }63 if (root.failFast) {64 throw AssertionError("Fail fast groups can only contain test scopes!")65 }66 val group = GroupScopeImpl(67 idFor(description),68 root.path.resolve(description),69 root,70 skip,71 lifecycleManager,72 preserveExecutionOrder,73 failFast74 )75 root.addChild(group)76 val cachingMode = if (defaultCachingMode == CachingMode.INHERIT) {77 this.defaultCachingMode78 } else {79 defaultCachingMode80 }81 val collector = Collector(group, lifecycleManager, cachingMode, defaultTimeout)82 try {83 require(description.isNotEmpty()) { "Empty description for group." }84 body.invoke(collector)85 collector.finalize()86 } catch (e: Throwable) {87 collector.beforeGroup { throw e }88 group.addChild(89 TestScopeImpl(90 idFor("Group Failure"),91 root.path.resolve("Group Failure"),92 root,93 defaultTimeout,94 {},95 skip,96 lifecycleManager97 )98 )99 }100 }101 override fun test(description: String, skip: Skip, timeout: Long, body: suspend TestBody.() -> Unit) {102 require(description.isNotEmpty()) { "Empty description for test." }103 val test = TestScopeImpl(104 idFor(description),105 root.path.resolve(description),106 root,107 timeout,108 body,109 skip,110 lifecycleManager111 )112 root.addChild(test)113 }114 override fun beforeEachTest(fixture: Fixture) {115 root.beforeEachTest(fixture)116 }117 override fun afterEachTest(fixture: Fixture) {118 root.afterEachTest(fixture)119 }120 override fun beforeEachGroup(fixture: Fixture) {121 root.beforeEachGroup(fixture)122 }123 override fun afterEachGroup(fixture: Fixture) {124 root.afterEachGroup(fixture)125 }126 override fun beforeGroup(fixture: Fixture) {127 root.beforeGroup(fixture)128 }129 override fun afterGroup(fixture: Fixture) {130 root.afterGroup(fixture)131 }132 private fun idFor(description: String): ScopeId {133 val current = ids.getOrPut(description) { 0 } + 1134 ids[description] = current135 return ScopeId(ScopeType.Scope, if (current > 1) "$description [$current]" else description)136 }137}...

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:


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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?