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

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

build.gradle.kts

Source:build.gradle.kts Github

copy

Full Screen

...100 reports {101 html.destination = file("${html.destination}/functional")102 junitXml.destination = file("${junitXml.destination}/functional")103 }104 timeout.set(Duration.ofMinutes(2))105}106gradlePlugin {107 testSourceSets(integrationTest)108}109val sourcesJar by tasks.registering(Jar::class) {110 dependsOn(JavaPlugin.CLASSES_TASK_NAME)111 group = JavaBasePlugin.DOCUMENTATION_GROUP112 description = "Assembles sources JAR"113 classifier = "sources"114 from(sourceSets.main.get().allSource)115}116val javadocJar by tasks.registering(Jar::class) {117 dependsOn(JavaPlugin.JAVADOC_TASK_NAME)118 group = JavaBasePlugin.DOCUMENTATION_GROUP...

Full Screen

Full Screen

DetoxSingleTapSpec.kt

Source:DetoxSingleTapSpec.kt Github

copy

Full Screen

1package com.wix.detox.espresso.action2import android.view.MotionEvent3import androidx.test.espresso.UiController4import androidx.test.espresso.action.Tapper5import com.nhaarman.mockitokotlin2.*6import com.wix.detox.espresso.common.MotionEvents7import org.assertj.core.api.Assertions.assertThat8import org.spekframework.spek2.Spek9import org.spekframework.spek2.style.specification.describe10private fun dontCareCoordinates() = FloatArray(2) { 0f }11private fun dontCarePrecision() = FloatArray(2) { 0f }12private fun fancyCoordinates() = FloatArray(2) { index -> ((index + 1) * 100).toFloat() }13private fun fancyPrecision() = FloatArray(2) { index -> ((index + 1) * 1000).toFloat() }14private const val DEFAULT_EVENT_TIME = 1000L15object DetoxSingleTapSpec: Spek({16 describe("Detox single-tapper replacement for Espresso") {17 lateinit var uiController: UiController18 lateinit var downEvent: MotionEvent19 lateinit var upEvent: MotionEvent20 lateinit var motionEvents: MotionEvents21 beforeEachTest {22 uiController = mock()23 downEvent = mock(name = "downEventMock") {24 on { eventTime }.doReturn(DEFAULT_EVENT_TIME)25 }26 upEvent = mock(name = "upEventMock")27 motionEvents = mock {28 on { obtainDownEvent(any(), any(), any()) }.doReturn(downEvent)29 on { obtainUpEvent(eq(downEvent), any(), any(), any()) }.doReturn(upEvent)30 }31 }32 fun uut() = DetoxSingleTap(motionEvents)33 fun uut(tapTimeout: Long) = DetoxSingleTap(motionEvents, tapTimeout)34 it("should send an down-up events sequence") {35 val coordinates = dontCareCoordinates()36 val precision = dontCarePrecision()37 uut().sendTap(uiController, coordinates, precision, 0, 0)38 verify(uiController).injectMotionEventSequence(arrayListOf(downEvent, upEvent))39 }40 it("should create down event with proper coordinates and precision") {41 val coordinates = fancyCoordinates()42 val precision = fancyPrecision()43 uut().sendTap(uiController, coordinates, precision, 0, 0)44 verify(motionEvents).obtainDownEvent(coordinates[0], coordinates[1], precision)45 }46 it("should create up event with proper coordinates") {47 val coordinates = fancyCoordinates()48 val precision = fancyPrecision()49 uut().sendTap(uiController, coordinates, precision, 0, 0)50 verify(motionEvents).obtainUpEvent(eq(downEvent), any(), eq(coordinates[0]), eq(coordinates[1]))51 }52 it("should create up event with a reasonable time-gap (30ms)") {53 val expectedUpEventTime = DEFAULT_EVENT_TIME + 3054 val coordinates = dontCareCoordinates()55 val precision = dontCarePrecision()56 uut().sendTap(uiController, coordinates, precision, 0, 0)57 verify(motionEvents).obtainUpEvent(eq(downEvent), eq(expectedUpEventTime), any(), any())58 }59 it("should recycle down+up events") {60 val coordinates = dontCareCoordinates()61 val precision = dontCarePrecision()62 uut().sendTap(uiController, coordinates, precision, 0, 0)63 verify(downEvent).recycle()64 verify(upEvent).recycle()65 }66 it("should recycle down_up events even if ui-controller throws") {67 whenever(uiController.injectMotionEventSequence(any())).doThrow(RuntimeException("exceptionMock"))68 val coordinates = dontCareCoordinates()69 val precision = dontCarePrecision()70 // TODO retry integrating https://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html71 var err: Exception? = null72 try {73 uut().sendTap(uiController, coordinates, precision, 0, 0)74 } catch (e: Exception) {75 err = e76 }77 assertThat(err).isNotNull()78 verify(downEvent).recycle()79 verify(upEvent).recycle()80 }81 it("should return failure if ui-controller fails") {82 whenever(uiController.injectMotionEventSequence(any())).doReturn(false)83 val coordinates = dontCareCoordinates()84 val precision = dontCarePrecision()85 val result = uut().sendTap(uiController, coordinates, precision, 0, 0)86 assertThat(result).isEqualTo(Tapper.Status.FAILURE)87 }88 it("should return success") {89 whenever(uiController.injectMotionEventSequence(any())).doReturn(true)90 val coordinates = dontCareCoordinates()91 val precision = dontCarePrecision()92 val result = uut().sendTap(uiController, coordinates, precision, 0, 0)93 assertThat(result).isEqualTo(Tapper.Status.SUCCESS)94 }95 it("should manage without inputDevice and buttonState args") {96 val coordinates = dontCareCoordinates()97 val precision = dontCarePrecision()98 uut().sendTap(uiController, coordinates, precision)99 verify(uiController).injectMotionEventSequence(arrayListOf(downEvent, upEvent))100 }101 it("should idle-wait the tap-registration period following a successful tap injection") {102 whenever(uiController.injectMotionEventSequence(any())).doReturn(true)103 val expectedWait = 111L104 val coordinates = dontCareCoordinates()105 val precision = dontCarePrecision()106 uut(expectedWait).sendTap(uiController, coordinates, precision, 0, 0)107 verify(uiController).loopMainThreadForAtLeast(eq(expectedWait))108 }109 it("should not idle-wait the tap-registration period if tap injection fails") {110 whenever(uiController.injectMotionEventSequence(any())).doReturn(false)111 val coordinates = dontCareCoordinates()112 val precision = dontCarePrecision()113 uut(111L).sendTap(uiController, coordinates, precision, 0, 0)114 verify(uiController, never()).loopMainThreadForAtLeast(any())115 }116 }117})...

Full Screen

Full Screen

example.gradle.kts

Source:example.gradle.kts Github

copy

Full Screen

...73 reports {74 html.destination = file("${html.destination}/functional")75 junitXml.destination = file("${junitXml.destination}/functional")76 }77 timeout.set(Duration.ofMinutes(2))78}79val sourcesJar by tasks.registering(Jar::class) {80 group = JavaBasePlugin.DOCUMENTATION_GROUP81 description = "Assembles sources JAR"82 classifier = "sources"83 from(sourceSets.main.get().allSource)84}85tasks {86 withType<KotlinCompile>().configureEach {87 kotlinOptions.jvmTarget = "1.8"88 }89 withType<Test>().configureEach {90 useJUnitPlatform {91 includeEngines("spek2")...

Full Screen

Full Screen

Executor.kt

Source:Executor.kt Github

copy

Full Screen

...44 val job = GlobalScope.async {45 scope.before()46 scope.execute()47 }48 val exception = withTimeout(scope.timeout) {49 try {50 job.await()51 null52 } catch (e: Throwable) {53 e54 }55 }56 if (exception != null) {57 throw exception58 }59 }60 }61 }62 } finally {...

Full Screen

Full Screen

Collectors.kt

Source:Collectors.kt Github

copy

Full Screen

...63 )64 )65 }66 }67 override fun test(description: String, skip: Skip, timeout: Long, body: TestBody.() -> Unit) {68 val test = TestScopeImpl(69 idFor(description),70 root.path.resolve(description),71 root,72 timeout,73 body,74 skip,75 lifecycleManager76 )77 root.addChild(test)78 }79 override fun beforeEachTest(callback: () -> Unit) {80 fixtures.registerBeforeEachTest(root, callback)81 }82 override fun afterEachTest(callback: () -> Unit) {83 fixtures.registerAfterEachTest(root, callback)84 }85 override fun beforeGroup(callback: () -> Unit) {86 fixtures.registerBeforeGroup(root, callback)...

Full Screen

Full Screen

Scopes.kt

Source:Scopes.kt Github

copy

Full Screen

...64class TestScopeImpl(65 id: ScopeId,66 path: Path,67 override val parent: GroupScope,68 val timeout: Long,69 private val body: TestBody.() -> Unit,70 skip: Skip,71 lifecycleManager: LifecycleManager72) : ScopeImpl(id, path, skip, lifecycleManager), TestScope {73 override fun before() = lifecycleManager.beforeExecuteTest(this)74 override fun execute() {75 body.invoke(object : TestBody {76 override fun <T> memoized(): MemoizedValue<T> {77 return MemoizedValueReader(this@TestScopeImpl)78 }79 })80 }81 override fun after() = lifecycleManager.afterExecuteTest(this)82}...

Full Screen

Full Screen

SpekRuntime.kt

Source:SpekRuntime.kt Github

copy

Full Screen

1package org.spekframework.spek2.runtime2import org.spekframework.spek2.Spek3import org.spekframework.spek2.dsl.Skip4import org.spekframework.spek2.lifecycle.CachingMode5import org.spekframework.spek2.runtime.execution.DiscoveryRequest6import org.spekframework.spek2.runtime.execution.DiscoveryResult7import org.spekframework.spek2.runtime.execution.ExecutionRequest8import org.spekframework.spek2.runtime.lifecycle.LifecycleManager9import org.spekframework.spek2.runtime.scope.*10import org.spekframework.spek2.runtime.util.ClassUtil11private const val DEFAULT_TIMEOUT = 10000L12class SpekRuntime {13 fun discover(discoveryRequest: DiscoveryRequest): DiscoveryResult {14 val scopes = discoveryRequest.context.getTests()15 .map { testInfo ->16 val matchingPath = discoveryRequest.paths.firstOrNull { it.intersects(testInfo.path) }17 testInfo to matchingPath18 }19 .filter { (_, matchingPath) -> matchingPath != null }20 .map { (testInfo, matchingPath) ->21 checkNotNull(matchingPath)22 val spec = resolveSpec(testInfo.createInstance(), testInfo.path)23 spec.filterBy(matchingPath)24 spec25 }26 .filter { spec -> !spec.isEmpty() }27 return DiscoveryResult(scopes)28 }29 fun execute(request: ExecutionRequest) = Executor().execute(request)30 private fun resolveSpec(instance: Spek, path: Path): GroupScopeImpl {31 val fixtures = FixturesAdapter()32 val lifecycleManager = LifecycleManager().apply {33 addListener(fixtures)34 }35 val (packageName, className) = ClassUtil.extractPackageAndClassNames(instance::class)36 val qualifiedName = if (packageName.isNotEmpty()) {37 "$packageName.$className"38 } else {39 className40 }41 val classScope = GroupScopeImpl(ScopeId(ScopeType.Class, qualifiedName), path, null, Skip.No, lifecycleManager, false)42 val collector = Collector(classScope, lifecycleManager, fixtures, CachingMode.TEST, DEFAULT_TIMEOUT)43 try {44 instance.root.invoke(collector)45 } catch (e: Exception) {46 collector.beforeGroup { throw e }47 classScope.addChild(TestScopeImpl(48 ScopeId(ScopeType.Scope, "Discovery failure"),49 path.resolve("Discovery failure"),50 classScope,51 DEFAULT_TIMEOUT,52 {},53 Skip.No,54 lifecycleManager55 ))56 }57 return classScope58 }59}...

Full Screen

Full Screen

timeout.kt

Source:timeout.kt Github

copy

Full Screen

1package org.spekframework.spek2.runtime2actual fun getGlobalTimeoutSetting(default: Long): Long {3 val override = System.getProperty("spek2.execution.test.timeout")?.toLong()4 return override ?: default5}6actual fun isParallelDiscoveryEnabled(default: Boolean): Boolean {7 return System.getProperty("spek2.discovery.parallel.enabled") != null || default8}9actual fun isParallelExecutionEnabled(default: Boolean): Boolean {10 return System.getProperty("spek2.execution.parallel.enabled") != null || default11}12actual fun getExecutionParallelism(): Int {13 return Runtime.getRuntime().availableProcessors()14}15actual fun isDebuggingEnabled(default: Boolean): Boolean {16 return System.getProperty("spek2.debug.enabled") != null || default17}...

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful