How to use listener method of io.kotest.core.TestConfiguration class

Best Kotest code snippet using io.kotest.core.TestConfiguration.listener

TransferGeneratorTest.kt

Source:TransferGeneratorTest.kt Github

copy

Full Screen

1package com.ninety.nine.test.transfer2import com.ninety.nine.main.*3import io.kotest.core.config.AbstractProjectConfig4import io.kotest.core.extensions.Extension5import io.kotest.core.listeners.TestListener6import io.kotest.core.spec.style.FunSpec7import io.kotest.matchers.*8import io.kotest.matchers.doubles.shouldBeLessThan9import io.kotest.matchers.string.shouldMatch10import io.kotest.spring.SpringAutowireConstructorExtension11import io.kotest.spring.SpringListener12import org.iban4j.IbanUtil13import org.springframework.beans.factory.annotation.Autowired14import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer15import org.springframework.boot.test.context.SpringBootTest16import org.springframework.boot.test.context.TestConfiguration17import org.springframework.test.context.ActiveProfiles18import org.springframework.test.context.ContextConfiguration19import java.util.concurrent.ThreadLocalRandom20class ProjectConfig : AbstractProjectConfig() {21 override fun extensions(): List<Extension> = listOf(SpringAutowireConstructorExtension)22}23fun hasProperLetter() = object : Matcher<String> {24 private val NIF_CHARACTERS = "TRWAGMYFPDXBNJZSQVHLCKE"25 fun isAValidNIF(nif: String): Boolean {26 val number = nif.substring(0, nif.length - 1).toLongOrNull()27 return when {28 number == null -> false29 nif.length != 9 -> false30 else -> nif[nif.length - 1] == NIF_CHARACTERS[(number % 23).toInt()]31 }32 }33 override fun test(value: String) =34 MatcherResult(35 isAValidNIF(value),36 "String $value should has proper letter",37 "String $value should not has a proper letter"38 )39}40@SpringBootTest41@ActiveProfiles("test")42@ContextConfiguration(43 initializers = [ConfigFileApplicationContextInitializer::class],44 classes = [TestConfiguration::class, TransferConfiguration::class, NIFGenerator::class]45)46class NIFCustomerGeneratorTest(private val generator: NIFGenerator, private val configuration: TransferConfiguration) :47 FunSpec() {48 override fun listeners(): List<TestListener> {49 return listOf(SpringListener)50 }51 init {52 test("Well formatted NIF should have 8 digits and one character").config(invocations = 10) {53 val randomPosition = ThreadLocalRandom.current().nextInt(0, configuration.people)54 generator.generateWell(randomPosition) shouldMatch "([a-z]|[A-Z]|[0-9])[0-9]{7}([a-z]|[A-Z]|[0-9])"55 }56 test("Well formatted NIF should have the proper last character").config(invocations = 10) {57 val randomPosition = ThreadLocalRandom.current().nextInt(0, configuration.people)58 generator.generateWell(randomPosition) should hasProperLetter()59 }60 test("Wrong formatted NIF should have 8 digits and one character").config(invocations = 10) {61 generator.generateWrong() shouldMatch "([a-z]|[A-Z]|[0-9])[0-9]{7}([a-z]|[A-Z]|[0-9])"62 }63 test("Wrong formatted NIF should not have the proper last character").config(invocations = 10) {64 generator.generateWrong() shouldNot hasProperLetter()65 }66 }67}68fun isAProperIban() = object : Matcher<String> {69 fun isValid(value: String): Boolean {70 return try {71 IbanUtil.validate(value)72 true73 } catch (ex: Exception) {74 false75 }76 }77 override fun test(value: String) =78 MatcherResult(79 isValid(value),80 "String $value should be proper iban",81 "String $value should not be proper iban"82 )83}84@SpringBootTest85@ActiveProfiles("test")86@ContextConfiguration(87 initializers = [ConfigFileApplicationContextInitializer::class],88 classes = [TestConfiguration::class, TransferConfiguration::class, IbanGenerator::class]89)90class IbanCustomerGeneratorTest(91 private val configuration: TransferConfiguration, private val generator: IbanGenerator92) : FunSpec() {93 override fun listeners(): List<TestListener> {94 return listOf(SpringListener)95 }96 init {97 test("Well formatted IBAN").config(invocations = 50) {98 val randomPosition = ThreadLocalRandom.current().nextInt(0, configuration.people)99 generator.generateWell(randomPosition) should isAProperIban()100 }101 test("Wrong formatted IBAN").config(invocations = 50) {102 generator.generateWrong() shouldNot isAProperIban()103 }104 }105}106fun isAValidCurrencyName(configuration: TransferConfiguration) = object : Matcher<String> {107 private val validCurrencies = configuration.currencies108 override fun test(value: String) =109 MatcherResult(110 validCurrencies.contains(value),111 "String $value is not a valid currency",112 "String $value should not be a valid currency"113 )114}115fun isAInvalidCurrencyName() = object : Matcher<String> {116 private val badCurrencyNames = arrayOf("SDU", "RUE", "GB", "CFH", "BUR", "KK", "KES")117 override fun test(value: String) =118 MatcherResult(119 badCurrencyNames.contains(value),120 "String $value is a valid currency",121 "String $value should be a valid currency"122 )123}124@SpringBootTest125@ActiveProfiles("test")126@ContextConfiguration(127 initializers = [ConfigFileApplicationContextInitializer::class],128 classes = [TestConfiguration::class, ConfigFileApplicationContextInitializer::class, CurrencyNameCustomGenerator::class, TransferConfiguration::class]129)130class CurrencyNameCustomerGeneratorTest(131 private val configuration: TransferConfiguration,132 private val generator: CurrencyNameCustomGenerator133) : FunSpec() {134 override fun listeners(): List<TestListener> {135 return listOf(SpringListener)136 }137 init {138 test("Valid currencies") {139 generator.checkCurrencies()140 }141 test("Valid currency").config(invocations = 50) {142 generator.generateWell() should isAValidCurrencyName(configuration)143 }144 test("Wrong valid currency").config(invocations = 50) {145 generator.generateWrong() should isAInvalidCurrencyName()146 }147 }148}149@SpringBootTest150@ActiveProfiles("test")151@ContextConfiguration(152 initializers = [ConfigFileApplicationContextInitializer::class],153 classes = [TestConfiguration::class, ConfigFileApplicationContextInitializer::class, CurrencyAmountCustomGenerator::class, TransferConfiguration::class]154)155class CurrencyAmountCustomerGeneratorTest(156 private val configuration: TransferConfiguration,157 private val generator: CurrencyAmountCustomGenerator158) : FunSpec() {159 override fun listeners(): List<TestListener> {160 return listOf(SpringListener)161 }162 init {163 test("Valid currency").config(invocations = 1000) {164 generator.generateWell().toDouble() shouldBeLessThan configuration.maxAmount165 }166 test("Wrong valid currency") {167 generator.generateWrong() shouldBe "N/A"168 }169 }170}171@SpringBootTest172@ActiveProfiles("test")173@ContextConfiguration(174 initializers = [ConfigFileApplicationContextInitializer::class],175 classes = [TestConfiguration::class,176 ConfigFileApplicationContextInitializer::class,177 TransferConfiguration::class,178 IbanGenerator::class,179 NIFGenerator::class,180 PersonFieldCustomGenerator::class]181)182class PersonFieldCustomerGeneratorTest(private val generator: PersonFieldCustomGenerator) : FunSpec() {183 override fun listeners(): List<TestListener> {184 return listOf(SpringListener)185 }186 init {187 test("Valid Person Field").config(invocations = 50) {188 val badGeneratedPersonField = generator.generateWell()189 val splitPersonField = badGeneratedPersonField.split("\t");190 splitPersonField.size shouldBe 2191 splitPersonField[0] should isAProperIban()192 splitPersonField[1] should hasProperLetter()193 }194 test("Wrong Person Field").config(invocations = 50) {195 val badGeneratedPersonField = generator.generateWrong()196 val splitPersonField = badGeneratedPersonField.split("\t");197 splitPersonField.size shouldBe 2198 splitPersonField[0] shouldNot isAProperIban()199 splitPersonField[1] shouldNot hasProperLetter()200 }201 }202}203fun isAValidTransfer() = object : Matcher<String> {204 private fun isValidTransfer(value: String): Boolean {205 return value == TransferGenerator.MALFORMED_LINE ||206 value.isBlank() ||207 value.split("\t").size >= 2208 }209 override fun test(value: String) =210 MatcherResult(211 isValidTransfer(value),212 "String \"$value\" is not a valid transfer line",213 "String \"$value\" should not be a valid transfer line"214 )215}216@SpringBootTest217@ActiveProfiles("test")218@ContextConfiguration(219 initializers = [ConfigFileApplicationContextInitializer::class],220 classes = [TestConfiguration::class,221 ConfigFileApplicationContextInitializer::class,222 TransferConfiguration::class,223 IbanGenerator::class,224 NIFGenerator::class,225 PersonFieldCustomGenerator::class,226 CurrencyNameCustomGenerator::class,227 CurrencyAmountCustomGenerator::class,228 TransferGenerator::class]229)230class TransferGeneratorTest(private val generator: TransferGenerator) : FunSpec() {231 override fun listeners(): List<TestListener> {232 return listOf(SpringListener)233 }234 init {235 test("Valid Transfer Line").config(invocations = 500) {236 generator.generate() should isAValidTransfer()237 }238 }239}...

Full Screen

Full Screen

TransferParserTest.kt

Source:TransferParserTest.kt Github

copy

Full Screen

2import com.ninety.nine.main.mongouploader.*3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.config.AbstractProjectConfig5import io.kotest.core.extensions.Extension6import io.kotest.core.listeners.TestListener7import io.kotest.core.spec.style.FunSpec8import io.kotest.matchers.doubles.shouldBeExactly9import io.kotest.spring.SpringAutowireConstructorExtension10import io.kotest.spring.SpringListener11import org.iban4j.Iban12import org.javamoney.moneta.FastMoney13import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer14import org.springframework.boot.test.context.SpringBootTest15import org.springframework.boot.test.context.TestConfiguration16import org.springframework.test.context.ActiveProfiles17import org.springframework.test.context.ContextConfiguration18import java.text.DecimalFormat19import java.util.concurrent.ThreadLocalRandom20import javax.money.convert.MonetaryConversions21class ProjectConfig : AbstractProjectConfig() {22 override fun extensions(): List<Extension> = listOf(SpringAutowireConstructorExtension)23}24@SpringBootTest25@ActiveProfiles("test")26@ContextConfiguration(27 initializers = [ConfigFileApplicationContextInitializer::class],28 classes = [TestConfiguration::class, IbanParser::class]29)30class IbanParserGeneratorTest(private val parser: IbanParser) : FunSpec() {31 override fun listeners(): List<TestListener> {32 return listOf(SpringListener)33 }34 init {35 test("Test throw exception because is a bad Iban").config(invocations = 10) {36 val iban = Iban.random().toString()37 val randomPosition = ThreadLocalRandom.current().nextInt(0, iban.length)38 val badIban = iban.replace(iban[randomPosition].toString(), "")39 shouldThrow<ParsingTransferException> {40 parser.parse(badIban)41 }42 }43 test("Test well processed IBANs").config(invocations = 100) {44 val goodIban = Iban.random().toString()45 parser.parse(goodIban)46 }47 }48}49@SpringBootTest50@ActiveProfiles("test")51@ContextConfiguration(52 initializers = [ConfigFileApplicationContextInitializer::class],53 classes = [TestConfiguration::class, NIFParser::class]54)55class NifParserGeneratorTest(private val parser: NIFParser) : FunSpec() {56 companion object {57 private const val NIF_CHARACTERS = "TRWAGMYFPDXBNJZSQVHLCKE"58 private const val MAXIMUM_NUMBER_NIF = 9999999959 }60 private fun calculateNif(): String {61 val randomNIF =62 ThreadLocalRandom.current().nextInt(63 1000,64 MAXIMUM_NUMBER_NIF65 )66 val char = NIF_CHARACTERS[randomNIF % NIF_CHARACTERS.length]67 return String.format("%08d", randomNIF) + char68 }69 private fun calculateBadNif(): String {70 val randomNIF =71 ThreadLocalRandom.current().nextInt(72 1000,73 MAXIMUM_NUMBER_NIF74 )75 val char = NIF_CHARACTERS[(randomNIF + 1) % NIF_CHARACTERS.length]76 return String.format("%08d", randomNIF) + char77 }78 override fun listeners(): List<TestListener> {79 return listOf(SpringListener)80 }81 init {82 test("Test throw exception because it is a bad nif").config(invocations = 10) {83 val nif = calculateBadNif()84 shouldThrow<ParsingTransferException> {85 parser.parse(nif)86 }87 }88 test("Test well processed NIFs").config(invocations = 100) {89 val nif = calculateNif()90 parser.parse(nif)91 }92 }93}94@SpringBootTest95@ActiveProfiles("test")96@ContextConfiguration(97 initializers = [ConfigFileApplicationContextInitializer::class],98 classes = [TestConfiguration::class, CurrencyAmountParser::class]99)100class CurrencyAmountParserGeneratorTest(private val parser: CurrencyAmountParser) : FunSpec() {101 override fun listeners(): List<TestListener> {102 return listOf(SpringListener)103 }104 private val currencyNames = arrayOf("USD", "EUR", "GBP", "CHF", "RUB", "DKK", "SEK")105 private val badCurrencyNames = arrayOf("SDU", "RUE", "GB", "CFH", "BUR", "KK", "EKS")106 private fun getRandom(array: Array<String>): String {107 val randomCurrencyPosition = ThreadLocalRandom.current().nextInt(0, array.size)108 return array[randomCurrencyPosition]109 }110 private fun getRandomCurrency(): String {111 return getRandom(currencyNames)112 }113 private fun getRandomBadCurrency(): String {114 return getRandom(badCurrencyNames)115 }116 private fun getRandomAmount(): Double {117 return ThreadLocalRandom.current().nextDouble(0.00, 10000.00)118 }119 init {120 test("Test throw exception because is a bad currency").config(invocations = 10) {121 val badCurrency: String = getRandomBadCurrency()122 val amount: String = getRandomAmount().toString()123 shouldThrow<ParsingTransferException> {124 parser.parse(badCurrency, amount)125 }126 }127 test("Test throw exception because is a bad amount").config(invocations = 10) {128 val currency = getRandomCurrency()129 shouldThrow<ParsingTransferException> {130 parser.parse(currency, currency)131 }132 }133 test("Test well processed currency and amount").config(invocations = 1000) {134 val amount = getRandomAmount().toString()135 val currency = getRandomCurrency()136 parser.parse(amount, currency)137 parser.parse(currency, amount)138 }139 }140}141@SpringBootTest()142@ActiveProfiles("test")143@ContextConfiguration(144 initializers = [ConfigFileApplicationContextInitializer::class],145 classes = [TransferParser::class, CurrencyAmountParser::class, IbanParser::class, NIFParser::class, CustomDateTimeFormatter::class]146)147class TransferParserGeneratorTest(private val parser: TransferParser) : FunSpec() {148 companion object{149 private val conversionEUR = MonetaryConversions.getConversion("EUR")150 private val df = DecimalFormat("0.00")151 }152 override fun listeners(): List<TestListener> {153 return listOf(SpringListener)154 }155 private fun getEurConversion(amount: Double, currency: String): Double{156 val currentMoney: FastMoney = FastMoney.of(amount, currency)157 val eurConversion: FastMoney = currentMoney.with(conversionEUR)158 return df.format(eurConversion.number.doubleValueExact()).toDouble()159 }160 init {161 test("Test throw exception because is a bad date") {162 val testLine = "\t95117.36\tCHF"163 shouldThrow<ParsingTransferException> {164 parser.parse("", testLine)165 }166 }...

Full Screen

Full Screen

Resource.kt

Source:Resource.kt Github

copy

Full Screen

...16import arrow.fx.coroutines.Platform17import arrow.fx.coroutines.Resource18import arrow.fx.coroutines.bracketCase19import arrow.fx.coroutines.continuations.ResourceScope20import io.kotest.core.listeners.TestListener21import io.kotest.core.spec.Spec22import kotlin.properties.ReadOnlyProperty23import kotlin.reflect.KProperty24import kotlinx.coroutines.Dispatchers25public suspend fun <A> Resource<A>.shouldBeResource(a: A): A =26 use { it shouldBe a }27public suspend fun <A> Resource<A>.shouldBeResource(expected: Resource<A>): A =28 zip(expected).use { (a, b) -> a shouldBe b }29/**30 * ensures that all finalizers of [resource] are invoked for the given [TestConfiguration],31 * by registering a listener.32 *33 * ```kotlin34 * interface Database { // given a Dependency35 * fun isRunning(): Boolean36 * suspend fun version(): String?37 * }38 *39 * // and a Way to create it, here with Hikari and SqlDelight40 * fun database(hikari: HikariDataSource): Database =41 * object : Database {42 * override fun isRunning(): Boolean = hikari.isRunning43 * override suspend fun version(): String? =44 * hikari.queryOneOrNull("SHOW server_version;") { string() }45 * }46 *47 * fun hikari(): Resource<HikariDataSource> =48 * Resource.fromCloseable {49 * HikariDataSource(50 * HikariConfig().apply {51 * // config settings52 * }53 * )54 * }55 * fun sqlDelight(hikariDataSource: HikariDataSource): Resource<SqlDelight> =56 * Resource.fromCloseable { hikariDataSource.asJdbcDriver() }.map { driver -> SqlDelight(driver) }57 *58 * // we can define a Database Resource59 * fun database(): Resource<Database> =60 * hikari().flatMap { hikari ->61 * sqlDelight(hikari).map { sqlDelight -> database(hikari) }62 * }63 *64 * // and define Tests with our backend Application, here with Ktor65 * class HealthCheckSpec :66 * StringSpec({67 * val database: Database by resource(database())68 *69 * "healthy" {70 * testApplication {71 * application { app(database) }72 * val response = client.get("/health")73 * response.status shouldBe HttpStatusCode.OK74 * response.bodyAsText() shouldBe Json.encodeToString(HealthCheck("14.1"))75 * }76 * }77 * })78 * ```79 */80public fun <A> TestConfiguration.resource(resource: Resource<A>): ReadOnlyProperty<Any?, A> =81 TestResource(resource).also(::listener)82private class TestResource<A>(private val resource: Resource<A>) :83 TestListener, ResourceScope, ReadOnlyProperty<Any?, A> {84 private val value: AtomicRef<Option<A>> = AtomicRef(None)85 private val finalizers: AtomicRef<List<suspend (ExitCase) -> Unit>> = AtomicRef(emptyList())86 override suspend fun <A> Resource<A>.bind(): A =87 when (this) {88 is Resource.Dsl -> dsl.invoke(this@TestResource)89 is Resource.Allocate ->90 bracketCase(91 {92 val a = acquire()93 val finalizer: suspend (ExitCase) -> Unit = { ex: ExitCase -> release(a, ex) }94 finalizers.update(finalizer::prependTo)95 a...

Full Screen

Full Screen

FileGeneratorTest.kt

Source:FileGeneratorTest.kt Github

copy

Full Screen

1package com.ninety.nine.test.file2import com.ninety.nine.main.*3import io.kotest.core.listeners.TestListener4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.Matcher6import io.kotest.matchers.MatcherResult7import io.kotest.matchers.should8import io.kotest.spring.SpringListener9import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer10import org.springframework.boot.test.context.SpringBootTest11import org.springframework.boot.test.context.TestConfiguration12import org.springframework.test.context.ActiveProfiles13import org.springframework.test.context.ContextConfiguration14import java.io.File15fun checkFile(fileConfiguration: FileConfiguration) = object : Matcher<String> {16 private fun checkFile(value: String): Boolean {17 var lines: Long = 018 val file = File(value)19 if (!file.exists())20 return false21 file.forEachLine { ++lines }22 return lines < fileConfiguration.transferAmountLines23 }24 override fun test(value: String) =25 MatcherResult(26 checkFile(value),27 "String $value is not a valid transfer line",28 "String $value should not be a valid transfer line"29 )30}31@SpringBootTest32@ActiveProfiles("test")33@ContextConfiguration(34 initializers = [ConfigFileApplicationContextInitializer::class],35 classes = [TestConfiguration::class,36 ConfigFileApplicationContextInitializer::class,37 TransferConfiguration::class,38 IbanGenerator::class,39 NIFGenerator::class,40 PersonFieldCustomGenerator::class,41 CurrencyNameCustomGenerator::class,42 CurrencyAmountCustomGenerator::class,43 TransferGenerator::class]44)45class FileGeneratorTest(private val transferGenerator: TransferGenerator): FunSpec() {46 override fun listeners(): List<TestListener> {47 return listOf(SpringListener)48 }49 private val fileConfiguration = FileConfiguration()50 init {51 fileConfiguration.transferAmountLines = 10052 }53 private val generator =54 FileGenerator(fileConfiguration, transferGenerator)55 private fun deleteFile(fileName: String){56 File(fileName).delete();57 }58 init {59 test("File should be well created") {60 val fileName = generator.create()...

Full Screen

Full Screen

CanUseAdditionalExtensionSpec.kt

Source:CanUseAdditionalExtensionSpec.kt Github

copy

Full Screen

1package org.fluentlenium.adapter.kotest.describespec2import io.kotest.core.TestConfiguration3import io.kotest.core.extensions.Extension4import io.kotest.core.listeners.BeforeTestListener5import io.kotest.core.test.TestCase6import io.kotest.matchers.shouldBe7import org.fluentlenium.adapter.kotest.FluentDescribeSpec8import org.openqa.selenium.WebDriver9class CanUseAdditionalExtensionSpec : FluentDescribeSpec() {10 var beforeTestListenerRun = false11 override fun newWebDriver(): WebDriver {12 // This is invoked by the Fluentlenium Integration13 // with this assertion we ensure that our custom extension (below) already was run14 beforeTestListenerRun shouldBe true15 return super.newWebDriver()16 }17 fun registerFirst(vararg extensions: Extension) {18 val field = TestConfiguration::class.java.getDeclaredField("_extensions")...

Full Screen

Full Screen

setup.kt

Source:setup.kt Github

copy

Full Screen

1package com.tylerkindy.betrayal.db2import io.kotest.core.TestConfiguration3import io.kotest.core.listeners.ProjectListener4import io.kotest.core.spec.AutoScan5import org.jetbrains.exposed.sql.Database6import org.jetbrains.exposed.sql.Schema7import org.jetbrains.exposed.sql.SchemaUtils8import org.jetbrains.exposed.sql.transactions.TransactionManager9import org.jetbrains.exposed.sql.transactions.transaction10import org.jetbrains.exposed.sql.vendors.PostgreSQLDialect11import java.io.File12@AutoScan13object SetupDatabaseProjectListener : ProjectListener {14 override suspend fun beforeProject() {15 Database.registerJdbcDriver(16 "jdbc:tc:postgresql",17 "org.postgresql.Driver",...

Full Screen

Full Screen

PostgresTestListener.kt

Source:PostgresTestListener.kt Github

copy

Full Screen

1package no.nav.arbeidsgiver.notifikasjon.util2import io.kotest.core.TestConfiguration3import io.kotest.core.listeners.TestListener4import io.kotest.core.spec.Spec5import io.kotest.core.test.TestCase6import kotlinx.coroutines.runBlocking7import no.nav.arbeidsgiver.notifikasjon.infrastruktur.Database8fun TestConfiguration.testDatabase(config: Database.Config): Database =9 runBlocking {10 Database.openDatabase(11 config.copy(12 // https://github.com/flyway/flyway/issues/2323#issuecomment-80449581813 jdbcOpts = mapOf("preparedStatementCacheQueries" to 0)14 )15 )16 }17 .also { listener(PostgresTestListener(it)) }18class PostgresTestListener(private val database: Database): TestListener {19 override val name: String20 get() = "PostgresTestListener"21 override suspend fun beforeContainer(testCase: TestCase) {22 database.withFlyway {23 clean()24 migrate()25 }26 }27 override suspend fun afterSpec(spec: Spec) {28 database.close()29 }30}...

Full Screen

Full Screen

Extensions.kt

Source:Extensions.kt Github

copy

Full Screen

...4fun <T : Startable> T.perTest(): StartablePerTestListener<T> = StartablePerTestListener<T>(this)5fun <T : Startable> T.perSpec(): StartablePerSpecListener<T> = StartablePerSpecListener<T>(this)6fun <T : Startable> T.perProject(containerName: String): StartablePerProjectListener<T> = StartablePerProjectListener<T>(this, containerName)7fun <T : Startable> TestConfiguration.configurePerTest(startable: T): T {8 listener(StartablePerTestListener(startable))9 return startable10}11fun <T : Startable> TestConfiguration.configurePerSpec(startable: T): T {12 listener(StartablePerSpecListener(startable))13 return startable14}15fun <T : Startable> TestConfiguration.configurePerProject(startable: T, containerName: String): T {16 listener(StartablePerProjectListener(startable, containerName))17 return startable18}...

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1val listener = object : TestListener {2override fun beforeSpec(spec: Spec) {3println("beforeSpec")4}5override fun afterSpec(spec: Spec) {6println("afterSpec")7}8override fun beforeTest(testCase: TestCase) {9println("beforeTest")10}11override fun afterTest(testCase: TestCase, result: TestResult) {12println("afterTest")13}14}15TestConfiguration.listeners(listOf(listener))16val listener = object : TestListener {17override fun beforeSpec(spec: Spec) {18println("beforeSpec")19}20override fun afterSpec(spec: Spec) {21println("afterSpec")22}23override fun beforeTest(testCase: TestCase) {24println("beforeTest")25}26override fun afterTest(testCase: TestCase, result: TestResult) {27println("afterTest")28}29}30TestConfiguration.listeners(listOf(listener))

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.TestConfiguration2object MyTestConfiguration : TestConfiguration {3 override fun beforeSpecClass(spec: Spec, tests: List<Test>) {4 }5 override fun afterSpecClass(spec: Spec, results: Map<TestCase, TestResult>) {6 }7 override fun beforeTest(testCase: TestCase) {8 }9 override fun afterTest(testCase: TestCase, result: TestResult) {10 }11}12@Listeners(MyTestConfiguration)13class MySpec : FunSpec() {14 init {15 test("some test") {16 }17 }18}19import io.kotest.core.listeners.TestListener20object MyTestListener : TestListener {21 override suspend fun beforeSpec(spec: Spec) {22 }23 override suspend fun afterSpec(spec: Spec) {24 }25 override suspend fun beforeTest(testCase: TestCase) {26 }27 override suspend fun afterTest(testCase: TestCase, result: TestResult) {28 }29}30@Listeners(MyTestListener)31class MySpec : FunSpec() {32 init {33 test("some test") {34 }35 }36}37import io.kotest.core.listeners.ProjectListener38object MyProjectListener : ProjectListener {39 override suspend fun beforeProject() {40 }41 override suspend fun afterProject() {42 }43}44@Listeners(MyProjectListener)45class MySpec : FunSpec() {46 init {47 test("some test") {48 }49 }50}51import io.kotest.core.listeners.SpecListener52object MySpecListener : SpecListener {53 override suspend fun beforeSpec(spec: Spec) {54 }55 override suspend fun afterSpec(spec: Spec) {56 }57}58@Listeners(MySpecListener)59class MySpec : FunSpec() {60 init {61 test("some test") {62 }63 }64}

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1object : TestConfiguration {2override fun listeners(): List<TestListener> {3}4}5object : FunSpec() {6override fun listeners(): List<TestListener> {7}8}9object : Extension {10override fun listeners(): List<TestListener> {11}12}13object : SpecExtension {14override fun listeners(): List<TestListener> {15}16}17object : TestCaseExtension {18override fun listeners(): List<TestListener> {19}20}21object : TestListenerExtension {22override fun listeners(): List<TestListener> {23}24}25object : TestListenerExtension {26override fun listeners(): List<TestListener> {27}28}29object : TestCaseExtension {30override fun listeners(): List<TestListener> {31}32}33object : SpecExtension {34override fun listeners(): List<TestListener> {35}36}37object : Extension {38override fun listeners(): List<TestListener> {39}40}41object : FunSpec() {42override fun listeners(): List<TestListener> {43}44}45object : TestConfiguration {46override fun listeners(): List<TestListener> {47}48}49object : AbstractProjectConfig()

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful