How to use FunSpecContainerScope class of io.kotest.core.spec.style.scopes package

Best Kotest code snippet using io.kotest.core.spec.style.scopes.FunSpecContainerScope

KotlinPoetAggregateCoderTest.kt

Source:KotlinPoetAggregateCoderTest.kt Github

copy

Full Screen

...163 import app.dokt.test.Arranger164 import com.airline.plane.app.PlaneCommands165 import com.airline.plane.app.PlaneTestAggregate166 import io.kotest.core.spec.style.FunSpec167 import io.kotest.core.spec.style.scopes.FunSpecContainerScope168 169 abstract class PlaneSpec(170 body: PlaneSpec.() -> Unit,171 private val testTailNo: String = "testTailNo"172 ) : FunSpec() {173 init {174 body()}175 176 val plane: Actor<PlaneCommands, Plane, PlaneEvent> =177 Actor(PlaneTestAggregate(Plane(testTailNo)))178 179 fun plane(tailNo: String = testTailNo, apply: (Events.() -> Unit)? = null) =180 Arranger<PlaneCommands, Plane, Events, PlaneEvent>(PlaneTestAggregate(Plane(tailNo)))(apply)181 182 fun gear(test: suspend FunSpecContainerScope.() -> Unit) = context("gear", test)183 184 fun pilot(test: suspend FunSpecContainerScope.() -> Unit) = context("pilot", test)185 }186 """187 }188 test("codeEvent") {189 coder.codeEvent() shouldCodeInPlaneApp """190 import app.dokt.app.RootEvent191 192 sealed interface PlaneEvent : RootEvent193 """194 }195 test("codeSerializer") {196 coder.codeSerializer() shouldCodeInPlaneApp """197 import com.airline.plane.Plane198 import kotlinx.serialization.KSerializer199 200 private val serializer: KSerializer<Plane> = Plane.serializer()201 """202 }203 test("codeService") {204 coder.codeService() shouldCodeInPlaneApp """205 import app.dokt.app.ApplicationService206 import app.dokt.app.To207 import com.airline.plane.Plane208 import com.airline.plane.PlaneEvent209 210 object PlaneService : ApplicationService<Plane, String, PlaneEvent>(Plane::class) {211 suspend fun gear(to: To<String>) = tx(to) { gear() }212 213 suspend fun pilot(214 to: To<String>,215 horizontal: Byte,216 vertical: Byte217 ) = tx(to) { pilot(horizontal, vertical) }218 }219 """220 }221 test("codeSpec") {222 coder.codeSpec() shouldCodeInPlane """223 import app.dokt.test.Actor224 import app.dokt.test.Arranger225 import com.airline.plane.app.PlaneCommands226 import com.airline.plane.app.PlaneTestAggregate227 import io.kotest.core.spec.style.FunSpec228 import io.kotest.core.spec.style.scopes.FunSpecContainerScope229 230 abstract class PlaneSpec(231 body: PlaneSpec.() -> Unit,232 private val testTailNo: String = "testTailNo"233 ) : FunSpec() {234 init {235 body()}236 237 val plane: Actor<PlaneCommands, Plane, PlaneEvent> =238 Actor(PlaneTestAggregate(Plane(testTailNo)))239 240 fun plane(tailNo: String = testTailNo, apply: (Events.() -> Unit)? = null) =241 Arranger<PlaneCommands, Plane, Events, PlaneEvent>(PlaneTestAggregate(Plane(tailNo)))(apply)242 243 fun gear(test: suspend FunSpecContainerScope.() -> Unit) = context("gear", test)244 245 fun pilot(test: suspend FunSpecContainerScope.() -> Unit) = context("pilot", test)246 }247 """248 }249 test("codeTestAggregate") {250 coder.codeTestAggregate() shouldCodeInPlaneApp """251 import app.dokt.test.TestAggregate252 import com.airline.plane.Events253 import com.airline.plane.Plane254 import com.airline.plane.PlaneEvent255 256 class PlaneTestAggregate(257 root: Plane258 ) : TestAggregate<Plane, Events, PlaneEvent>(root, serializer), PlaneCommands, Events {259 override fun gear() = command.gear()...

Full Screen

Full Screen

RepositoryTest.kt

Source:RepositoryTest.kt Github

copy

Full Screen

...29import com.ryanmoelter.ynab.SyncData30import com.ryanmoelter.ynab.database.Database31import io.kotest.assertions.throwables.shouldThrowAny32import io.kotest.core.spec.style.FunSpec33import io.kotest.core.spec.style.scopes.FunSpecContainerScope34import io.kotest.matchers.collections.shouldBeEmpty35import io.kotest.matchers.collections.shouldContainExactly36import io.kotest.matchers.collections.shouldHaveSingleElement37import io.kotest.matchers.shouldBe38class RepositoryTest : FunSpec({39 val serverDatabase = FakeYnabServerDatabase()40 val component = createFakeSplityComponent(serverDatabase)41 val localDatabase = component.database42 val repository = Repository(localDatabase, component.api, component.config)43 val setUpServerDatabase: Setup<FakeYnabServerDatabase> = { setUp -> serverDatabase.also(setUp) }44 val setUpLocalDatabase: Setup<Database> = { setUp -> localDatabase.also(setUp) }45 setUpServerDatabase {46 setUpBudgetsAndAccounts(47 fromBudget to listOf(FROM_ACCOUNT, FROM_TRANSFER_SOURCE_ACCOUNT),48 toBudget to listOf(TO_ACCOUNT)49 )50 }51 context("with filled SyncData") {52 setUpLocalDatabase {53 syncDataQueries.replaceOnly(54 SyncData(55 firstServerKnowledge = 0,56 firstBudgetId = FROM_BUDGET_ID,57 firstAccountId = FROM_ACCOUNT_ID,58 firstAccountPayeeId = FROM_ACCOUNT_PAYEE_ID,59 secondServerKnowledge = 0,60 secondBudgetId = TO_BUDGET_ID,61 secondAccountId = TO_ACCOUNT_ID,62 secondAccountPayeeId = TO_ACCOUNT_PAYEE_ID63 )64 )65 }66 fetchTransactionsPullsDataProperly(67 setUpServerDatabase,68 setUpLocalDatabase,69 localDatabase,70 repository71 )72 }73 context("with no SyncData") {74 fetchTransactionsPullsDataProperly(75 setUpServerDatabase,76 setUpLocalDatabase,77 localDatabase,78 repository79 )80 }81})82private suspend fun FunSpecContainerScope.fetchTransactionsPullsDataProperly(83 setUpServerDatabase: Setup<FakeYnabServerDatabase>,84 setUpLocalDatabase: Setup<Database>,85 localDatabase: Database,86 repository: Repository87) = context("fetchNewTransactions pulls data properly") {88 context("with empty server") {89 test("fetchNewTransactions does nothing") {90 repository.fetchNewTransactions()91 repository.getTransactionsByAccount(FROM_ACCOUNT_ID).shouldBeEmpty()92 }93 }94 context("with one unremarkable transaction on the server") {95 setUpServerDatabase {96 addOrUpdateTransactionsForAccount(...

Full Screen

Full Screen

UserApiTest.kt

Source:UserApiTest.kt Github

copy

Full Screen

...10import fanpoll.infra.base.i18n.Lang11import fanpoll.infra.base.json.toJsonString12import fanpoll.infra.base.response.InfraResponseCode13import integration.util.*14import io.kotest.core.spec.style.scopes.FunSpecContainerScope15import io.ktor.http.HttpMethod16import io.ktor.http.HttpStatusCode17import io.ktor.server.testing.TestApplicationEngine18import io.ktor.server.testing.setBody19import kotlinx.serialization.json.jsonPrimitive20import mu.KotlinLogging21import java.util.*22import kotlin.test.assertEquals23import kotlin.test.assertNotNull24val userApiTest: suspend TestApplicationEngine.(FunSpecContainerScope) -> Unit = { context ->25 val logger = KotlinLogging.logger {}26 lateinit var userId: UUID27 lateinit var runAsToken: UserRunAsToken28 val userAdmin1Form = CreateUserForm(29 "user-admin_1@test.com", "123456",30 true, ClubUserRole.Admin, "user-admin_1",31 Gender.Male, 2000, "user-admin_1@test.com", "0987654321", Lang.zh_TW32 )33 context.test("create admin user") {34 with(clubHandleSecuredRequest(35 HttpMethod.Post, "/users", ClubAuth.RootSource36 ) {37 setBody(userAdmin1Form.toJsonString())38 }) {...

Full Screen

Full Screen

NotificationTest.kt

Source:NotificationTest.kt Github

copy

Full Screen

...21import fanpoll.infra.notification.logging.NotificationMessageLogTable22import fanpoll.infra.notification.util.SendNotificationForm23import integration.util.clubHandleSecuredRequest24import integration.util.dataJsonObject25import io.kotest.core.spec.style.scopes.FunSpecContainerScope26import io.ktor.http.HttpMethod27import io.ktor.http.HttpStatusCode28import io.ktor.server.testing.TestApplicationEngine29import io.ktor.server.testing.setBody30import kotlinx.coroutines.delay31import kotlinx.serialization.json.jsonPrimitive32import mu.KotlinLogging33import org.jetbrains.exposed.sql.select34import java.util.*35import kotlin.test.assertEquals36import kotlin.test.assertNotNull37val notificationApiTest: suspend TestApplicationEngine.(FunSpecContainerScope) -> Unit = { context ->38 val logger = KotlinLogging.logger {}39 lateinit var userId: UUID40 lateinit var runAsToken: UserRunAsToken41 val notificationUser1Form = CreateUserForm(42 "notification-user_1@test.com", "123456",43 true, ClubUserRole.Admin, "notification-user_1",44 Gender.Male, 2000, "notification-user_1@test.com", "0987654321", Lang.zh_TW45 )46 context.test("send multi-notifications") {47 with(clubHandleSecuredRequest(48 HttpMethod.Post, "/users", ClubAuth.RootSource49 ) {50 setBody(notificationUser1Form.toJsonString())51 }) {...

Full Screen

Full Screen

KtorTestUtils.kt

Source:KtorTestUtils.kt Github

copy

Full Screen

...4package integration.util5import fanpoll.infra.base.json.json6import fanpoll.infra.base.response.*7import fanpoll.infra.main8import io.kotest.core.spec.style.scopes.FunSpecContainerScope9import io.ktor.application.Application10import io.ktor.server.engine.ApplicationEngineEnvironment11import io.ktor.server.testing.TestApplicationEngine12import io.ktor.server.testing.TestApplicationResponse13import io.ktor.server.testing.createTestEnvironment14import kotlinx.serialization.json.*15object SingleKtorTestApplicationEngine {16 val instance: TestApplicationEngine by lazy {17 TestApplicationEngine(createTestEnvironment()) {}.apply {18 start()19 application.main {20 listOf(SinglePostgreSQLContainer, SingleRedisContainer).forEach {21 it.configure(this)22 }23 }24 }25 }26}27fun TestApplicationResponse.jsonObject(): JsonObject = content?.let { json.parseToJsonElement(it).jsonObject }28 ?: error("response content is empty or not a json object")29fun TestApplicationResponse.code(): ResponseCode = jsonObject()["code"]?.let { json.decodeFromJsonElement(it) }30 ?: InfraResponseCode.OK31fun TestApplicationResponse.message(): String? = jsonObject()["message"]?.jsonPrimitive?.content32fun TestApplicationResponse.dataJson(): JsonElement? = jsonObject()["data"]33fun TestApplicationResponse.dataJsonObject(): JsonObject =34 dataJson()?.jsonObject ?: error("response data is neither exist or a json object")35fun TestApplicationResponse.dataJsonArray(): JsonArray =36 dataJson()?.jsonArray ?: error("response data is neither exist or a json array")37inline fun <reified T> TestApplicationResponse.data(): T = dataJsonObject().let { json.decodeFromJsonElement(it) }38inline fun <reified T> TestApplicationResponse.dataList(): List<T> = dataJsonArray().map { json.decodeFromJsonElement(it) }39fun TestApplicationResponse.response(): ResponseDTO = json.decodeFromJsonElement(jsonObject())40fun TestApplicationResponse.dataResponse(): DataResponseDTO = json.decodeFromJsonElement(jsonObject())41fun TestApplicationResponse.pagingDataResponse(): PagingDataResponseDTO = json.decodeFromJsonElement(jsonObject())42fun TestApplicationResponse.errorResponse(): ErrorResponseDTO = json.decodeFromJsonElement(jsonObject())43suspend fun <R> FunSpecContainerScope.withTestApplicationInKotestContext(44 moduleFunction: Application.() -> Unit,45 test: suspend TestApplicationEngine.(FunSpecContainerScope) -> R46): R {47 val context = this48 return withTestApplicationInKotestContext(createTestEnvironment()) {49 moduleFunction(application)50 test(context)51 }52}53suspend fun <R> FunSpecContainerScope.withTestApplicationInKotestContext(54 environment: ApplicationEngineEnvironment = createTestEnvironment(),55 configure: TestApplicationEngine.Configuration.() -> Unit = {},56 test: suspend TestApplicationEngine.(FunSpecContainerScope) -> R57): R {58 val context = this59 val engine = TestApplicationEngine(environment, configure)60 engine.start()61 try {62 return engine.test(context)63 } finally {64 engine.stop(0L, 0L)65 }66}...

Full Screen

Full Screen

FunSpecContainerScope.kt

Source:FunSpecContainerScope.kt Github

copy

Full Screen

...3import io.kotest.core.descriptors.append4import io.kotest.core.names.TestName5import io.kotest.core.spec.KotestTestScope6import io.kotest.core.test.TestScope7@Deprecated("This interface has been renamed to FunSpecContainerScope. Deprecated since 4.5")8typealias FunSpecContextScope = FunSpecContainerScope9@Deprecated("This interface has been renamed to FunSpecContainerScope. Deprecated since 5.0")10typealias FunSpecContainerContext = FunSpecContainerScope11/**12 * A context that allows tests to be registered using the syntax:13 *14 * context("some context")15 * test("some test")16 * test("some test").config(...)17 *18 */19@KotestTestScope20class FunSpecContainerScope(21 private val testScope: TestScope,22) : AbstractContainerScope(testScope) {23 /**24 * Adds a 'context' container test as a child of the current test case.25 */26 suspend fun context(name: String, test: suspend FunSpecContainerScope.() -> Unit) {27 registerContainer(TestName(name), false, null) { FunSpecContainerScope(this).test() }28 }29 /**30 * Adds a container test to this context expecting config.31 */32 @ExperimentalKotest33 fun context(name: String): ContainerWithConfigBuilder<FunSpecContainerScope> {34 return ContainerWithConfigBuilder(35 name = TestName(name),36 context = this,37 xdisabled = false,38 contextFn = { FunSpecContainerScope(it) }39 )40 }41 /**42 * Adds a disabled container test to this context.43 */44 suspend fun xcontext(name: String, test: suspend FunSpecContainerScope.() -> Unit) {45 registerContainer(TestName(name), true, null) { FunSpecContainerScope(this).test() }46 }47 /**48 * Adds a disabled container to this context, expecting config.49 */50 @ExperimentalKotest51 fun xcontext(name: String): ContainerWithConfigBuilder<FunSpecContainerScope> {52 return ContainerWithConfigBuilder(53 TestName(name),54 this,55 true56 ) { FunSpecContainerScope(it) }57 }58 /**59 * Adds a test case to this context, expecting config.60 */61 suspend fun test(name: String): TestWithConfigBuilder {62 TestDslState.startTest(testScope.testCase.descriptor.append(name))63 return TestWithConfigBuilder(64 name = TestName(name),65 context = this,66 xdisabled = false,67 )68 }69 /**70 * Adds a disabled test case to this context, expecting config....

Full Screen

Full Screen

FunSpecRootScope.kt

Source:FunSpecRootScope.kt Github

copy

Full Screen

...9 * Extends [RootScope] with dsl-methods for the 'fun spec' style.10 */11interface FunSpecRootScope : RootScope {12 /**13 * Adds a container [RootTest] that uses a [FunSpecContainerScope] as the test context.14 */15 fun context(name: String, test: suspend FunSpecContainerScope.() -> Unit) {16 addContainer(TestName("context ", name, false), false, null) { FunSpecContainerScope(this).test() }17 }18 /**19 * Adds a disabled container [RootTest] that uses a [FunSpecContainerScope] as the test context.20 */21 fun xcontext(name: String, test: suspend FunSpecContainerScope.() -> Unit) =22 addContainer(TestName("context ", name, false), true, null) { FunSpecContainerScope(this).test() }23 @ExperimentalKotest24 fun context(name: String): RootContainerWithConfigBuilder<FunSpecContainerScope> =25 RootContainerWithConfigBuilder(TestName("context ", name, false), false, this) { FunSpecContainerScope(it) }26 @ExperimentalKotest27 fun xcontext(name: String): RootContainerWithConfigBuilder<FunSpecContainerScope> =28 RootContainerWithConfigBuilder(TestName("context ", name, false), true, this) { FunSpecContainerScope(it) }29 /**30 * Adds a [RootTest], with the given name and config taken from the config builder.31 */32 fun test(name: String): RootTestWithConfigBuilder =33 RootTestWithConfigBuilder(this, TestName(name), xdisabled = false)34 /**35 * Adds a [RootTest], with the given name and default config.36 */37 fun test(name: String, test: suspend TestScope.() -> Unit) = addTest(TestName(name), false, null, test)38 /**39 * Adds a disabled [RootTest], with the given name and default config.40 */41 fun xtest(name: String, test: suspend TestScope.() -> Unit) = addTest(TestName(name), true, null, test)42 /**...

Full Screen

Full Screen

AccountSpec.kt

Source:AccountSpec.kt Github

copy

Full Screen

1package biz.bank.account2import app.dokt.test.Arranger3import biz.bank.account.app.*4import io.kotest.core.spec.style.FunSpec5import io.kotest.core.spec.style.scopes.FunSpecContainerScope6abstract class AccountSpec(body: AccountSpec.() -> Unit, private val testNumber: Iban) : FunSpec() {7 init { body() }8 val account get() =9 Arranger<AccountCommands, Account, Events, AccountEvent>(AccountTestAggregate(Account(testNumber)))()10 fun account(number: Iban = testNumber, apply: (Events.() -> Unit)? = null) =11 Arranger<AccountCommands, Account, Events, AccountEvent>(AccountTestAggregate(Account(number)))(apply)12 fun deposit(test: suspend FunSpecContainerScope.() -> Unit) = context("deposit", test)13 fun freeze(test: suspend FunSpecContainerScope.() -> Unit) = context("freeze", test)14 fun withdraw(test: suspend FunSpecContainerScope.() -> Unit) = context("withdraw", test)15}...

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 Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in FunSpecContainerScope

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful