From a92e3a1a939d983c7359f1aa4e878eee96288317 Mon Sep 17 00:00:00 2001 From: Nikolay Pachkov Date: Mon, 15 Jan 2024 21:23:35 +0100 Subject: [PATCH] KTL-671 feat: add kotlinx.coroutines.test --- build.gradle.kts | 1 + .../server/CoroutinesTestRunnerTest.kt | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/test/kotlin/com/compiler/server/CoroutinesTestRunnerTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 9341dfe8f..6018aca77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -116,6 +116,7 @@ dependencies { kotlinDependency("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") kotlinDependency("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.3") + kotlinDependency("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3") kotlinJsDependency("org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinVersion") kotlinJsDependency("org.jetbrains.kotlin:kotlin-dom-api-compat:$kotlinVersion") kotlinWasmDependency("org.jetbrains.kotlin:kotlin-stdlib-wasm-js:$kotlinVersion") diff --git a/src/test/kotlin/com/compiler/server/CoroutinesTestRunnerTest.kt b/src/test/kotlin/com/compiler/server/CoroutinesTestRunnerTest.kt new file mode 100644 index 000000000..21718bd5a --- /dev/null +++ b/src/test/kotlin/com/compiler/server/CoroutinesTestRunnerTest.kt @@ -0,0 +1,34 @@ +package com.compiler.server + +import com.compiler.server.base.BaseJUnitTest +import com.compiler.server.model.TestStatus +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + +class CoroutinesTestRunnerTest : BaseJUnitTest() { + @Test + fun `coroutines-test test`() { + val test = test(""" +import org.junit.Assert.* +import org.junit.Test +import kotlinx.coroutines.test.runTest +import kotlinx.coroutines.delay + +internal class SampleTest { + suspend fun fetchData(): String { + delay(1000L) + return "Hello world" + } + + @Test + fun dataShouldBeHelloWorld() = runTest { + val data = fetchData() + assertEquals("Hello world", data) + } +} + """.trimIndent() + ) + + Assertions.assertTrue(test.first().status == TestStatus.OK) + } +} \ No newline at end of file