How to use build class of io.kotest.core.factory package

Best Kotest code snippet using io.kotest.core.factory.build

PlantumlGradlePluginFunctionalSpec.kt

Source:PlantumlGradlePluginFunctionalSpec.kt Github

copy

Full Screen

...100 }101 usingExtension()102 usingTasks()103})104private fun canConfigurePlantUmlPlugin(name: String, extension: String, buildFile: String) =105 stringSpec {106 "can configure plantuml task using $name DSL" {107 // Setup the test build108 val projectDir = File("build/functionalTest/$name")109 projectDir.mkdirs()110 projectDir.resolve("settings.gradle$extension").writeText("")111 projectDir.resolve("build.gradle$extension").writeText(buildFile)112 projectDir.resolve("gradle.properties").writeText("org.gradle.unsafe.configuration-cache=true")113 projectDir.resolve("Hello.puml").writeText(114 """115 @startuml116 Bob->Alice : Hello World!117 @enduml118 """.trimIndent()119 )120 // Run the build121 val runner = GradleRunner.create().apply {122 forwardOutput()123 withPluginClasspath()124 withArguments("--rerun-tasks", "plantumlAll")125 withProjectDir(projectDir)126 }127 val result = runner.build()128 listOf(":plantumlAll", ":plantumlHello", ":plantumlHello2").forEach {129 val task = result.task(it)130 task.shouldNotBeNull()131 task.outcome shouldBe TaskOutcome.SUCCESS132 }133 listOf("Hello.svg", "Hello2.svg").forEach {134 val svg = File(projectDir, "svg/$it")135 svg.shouldExist()136 validateSVG(svg)137 }138 }139 }140private fun canUseGlobPattern(name: String, extension: String, buildFile: String) =141 stringSpec {142 "can use Glob pattern using $name DSL" {143 // Setup the test build144 val projectDir = File("build/functionalTest/$name")145 projectDir.mkdirs()146 projectDir.resolve("settings.gradle$extension").writeText("")147 projectDir.resolve("build.gradle$extension").writeText(buildFile)148 projectDir.resolve("gradle.properties").writeText("org.gradle.unsafe.configuration-cache=true")149 val pumlDir = File(projectDir, "puml")150 pumlDir.mkdirs()151 pumlDir.resolve("Hello.puml").writeText(152 """153 @startuml154 Bob->Alice : Hello World!155 @enduml156 """.trimIndent()157 )158 val pumlSubDir = File(pumlDir, "sub")159 pumlSubDir.mkdirs()160 pumlDir.resolve("Hello2.puml").writeText(161 """162 @startuml163 Bob->Alice : Hello World!164 @enduml165 """.trimIndent()166 )167 // Run the build168 val runner = GradleRunner.create().apply {169 forwardOutput()170 withPluginClasspath()171 withArguments("--rerun-tasks", "generateDiagrams", "--stacktrace")172 withProjectDir(projectDir)173 }174 val result = runner.build()175 listOf(":generateDiagrams").forEach {176 val task = result.task(it)177 task.shouldNotBeNull()178 task.outcome shouldBe TaskOutcome.SUCCESS179 }180 listOf("Hello.svg", "Hello2.svg").forEach {181 val svg = File(projectDir, "svg/$it")182 svg.shouldExist()183 validateSVG(svg)184 }185 }186 }187private fun validateSVG(file: File) {188 file.inputStream().buffered().use {...

Full Screen

Full Screen

NetworkResponseAdapterTest.kt

Source:NetworkResponseAdapterTest.kt Github

copy

Full Screen

...28 val retrofit = Retrofit.Builder()29 .addCallAdapterFactory(callAdapterFactory)30 .addConverterFactory(converterFactory)31 .baseUrl("http://localhost")32 .build()33 val callAdapter = callAdapterFactory.get(returnType, emptyArray(), retrofit)34 callAdapter shouldNotBe null35 callAdapter?.responseType() shouldBe String::class.java36 }37 it("should adapt a call correctly") {38 val converterFactory = StringConverterFactory()39 val callAdapterFactory = NetworkResponseAdapterFactory()40 val returnType = typeOf<Call<NetworkResponse<String, String>>>()41 val retrofit = Retrofit.Builder()42 .addCallAdapterFactory(callAdapterFactory)43 .addConverterFactory(converterFactory)44 .baseUrl("http://localhost")45 .build()46 val retrofitCall = CompletableCall<String>()47 val callAdapter = callAdapterFactory.get(returnType, emptyArray(), retrofit)48 callAdapter shouldNotBe null49 callAdapter.shouldBeInstanceOf<CallAdapter<String, Call<NetworkResponse<String, String>>>>()50 val adaptedCall = callAdapter.adapt(retrofitCall)51 adaptedCall.shouldBeInstanceOf<Call<NetworkResponse<String, String>>>()52 }53 }54 describe("E2E: ${NetworkResponseAdapter::class.java.simpleName}") {55 val client = OkHttpClient.Builder().callTimeout(Duration.ofMillis(100)).build()56 val server = MockWebServer()57 val retrofit = Retrofit.Builder()58 .addCallAdapterFactory(NetworkResponseAdapterFactory())59 .addConverterFactory(StringConverterFactory())60 .addConverterFactory(CrashyObjectConverterFactory())61 .client(client)62 .baseUrl(server.url("/"))63 .build()64 val service = retrofit.create(NetworkResponseAdapterService::class.java)65 beforeContainer {66 @Suppress("BlockingMethodInNonBlockingContext")67 server.start()68 }69 afterContainer {70 @Suppress("BlockingMethodInNonBlockingContext")71 server.close()72 }73 it("should return successful response as NetworkResponse.Success") {74 server.enqueue(75 MockResponse()76 .setResponseCode(200)77 .setBody("Test Message")...

Full Screen

Full Screen

DeferredNetworkResponseAdapterTest.kt

Source:DeferredNetworkResponseAdapterTest.kt Github

copy

Full Screen

...25 val retrofit = Retrofit.Builder()26 .addCallAdapterFactory(callAdapterFactory)27 .addConverterFactory(converterFactory)28 .baseUrl("http://localhost")29 .build()30 val callAdapter = callAdapterFactory.get(returnType, emptyArray(), retrofit)31 callAdapter shouldNotBe null32 callAdapter?.responseType() shouldBe String::class.java33 }34 it("should adapt a call correctly") {35 val converterFactory = StringConverterFactory()36 val callAdapterFactory = NetworkResponseAdapterFactory()37 val returnType = typeOf<Deferred<NetworkResponse<String, String>>>()38 val retrofit = Retrofit.Builder()39 .addCallAdapterFactory(callAdapterFactory)40 .addConverterFactory(converterFactory)41 .baseUrl("http://localhost")42 .build()43 val retrofitCall = CompletableCall<String>()44 val callAdapter = callAdapterFactory.get(returnType, emptyArray(), retrofit)45 callAdapter shouldNotBe null46 callAdapter.shouldBeInstanceOf<CallAdapter<String, Deferred<NetworkResponse<String, String>>>>()47 val adaptedCall = callAdapter.adapt(retrofitCall)48 @Suppress("DeferredResultUnused")49 adaptedCall.shouldBeInstanceOf<Deferred<NetworkResponse<String, String>>>()50 }51 }52 describe("E2E: ${DeferredNetworkResponseAdapter::class.java.simpleName}") {53 val client = OkHttpClient.Builder().callTimeout(Duration.ofMillis(100)).build()54 val server = MockWebServer()55 val retrofit = Retrofit.Builder()56 .addCallAdapterFactory(NetworkResponseAdapterFactory())57 .addConverterFactory(StringConverterFactory())58 .addConverterFactory(CrashyObjectConverterFactory())59 .client(client)60 .baseUrl(server.url("/"))61 .build()62 val service = retrofit.create(DeferredNetworkResponseService::class.java)63 beforeContainer {64 @Suppress("BlockingMethodInNonBlockingContext")65 server.start()66 }67 afterContainer {68 @Suppress("BlockingMethodInNonBlockingContext")69 server.close()70 }71 it("should return successful response as NetworkResponse.Success") {72 server.enqueue(73 MockResponse()74 .setResponseCode(200)75 .setBody("Test Message")...

Full Screen

Full Screen

CsvFileSourcedMeasurementConverterFactoryTests.kt

Source:CsvFileSourcedMeasurementConverterFactoryTests.kt Github

copy

Full Screen

1package com.github.jvmusin.universalconverter.converter.factory2import com.github.jvmusin.universalconverter.converter.conversionGraphFactory3import com.github.jvmusin.universalconverter.converter.weightFactory4import com.github.jvmusin.universalconverter.fraction.ComplexFraction5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.core.spec.style.BehaviorSpec7import io.kotest.engine.spec.tempfile8import io.kotest.matchers.shouldBe9import java.nio.file.Path10class CsvFileSourcedMeasurementConverterFactoryTests : BehaviorSpec() {11 private val converterFactory =12 CsvFileSourcedMeasurementConverterFactory(weightFactory, conversionGraphFactory)13 private fun writeRules(vararg rules: String): Path {14 return tempfile("rules", ".csv").apply { writeText(rules.joinToString("\n")) }.toPath()15 }16 private fun createConverter(vararg rules: String) = converterFactory.create(writeRules(*rules))17 init {18 Given("создание конвертера create") {19 When("всё хорошо") {20 Then("создаёт конвертер") {21 val converter = createConverter(22 "м,см,100",23 "мм,м,0.001",24 "км,м,1000",25 "час,мин,60",26 "мин,с,60"27 )28 val result = converter.convertFractions(29 ComplexFraction(listOf("км"), listOf()),30 ComplexFraction(listOf("мм"), listOf())31 )32 result.value shouldBe 1_000_00033 }34 }35 When("есть пустые строки") {36 Then("игнорирует их и создаёт конвертер") {37 val converter = createConverter(38 "",39 "м,см,100",40 "мм,м,0.001",41 " ",42 "км,м,1000",43 "час,мин,60",44 "мин,с,60",45 "\t \t ",46 "\t",47 )48 val result = converter.convertFractions(49 ComplexFraction(listOf("км"), listOf()),50 ComplexFraction(listOf("мм"), listOf())51 )52 result.value shouldBe 1_000_00053 }54 }55 When("есть пустой токен") {56 Then("бросает MeasurementConverterBuildException") {57 shouldThrow<MeasurementConverterBuildException> {58 createConverter(59 "м,см,100",60 "мм,м,0.001",61 ",м,1000",62 "час,мин,60",63 "мин,с,60"64 )65 }66 }67 }68 When("вместо трёх токенов два") {69 Then("бросает MeasurementConverterBuildException") {70 shouldThrow<MeasurementConverterBuildException> {71 createConverter(72 "м,см,100",73 "мм,м,0.001",74 "м,1000",75 "час,мин,60",76 "мин,с,60"77 )78 }79 }80 }81 When("вместо трёх токенов четыре") {82 Then("бросает MeasurementConverterBuildException") {83 shouldThrow<MeasurementConverterBuildException> {84 createConverter(85 "м,см,100",86 "мм,м,0.001",87 "км,м,1000,qq",88 "час,мин,60",89 "мин,с,60"90 )91 }92 }93 }94 When("не получается спарсить вес") {95 Then("бросает MeasurementConverterBuildException") {96 shouldThrow<MeasurementConverterBuildException> {97 createConverter(98 "м,см,100q",99 "мм,м,0.001",100 "км,м,1000",101 "час,мин,60",102 "мин,с,60"103 )104 }105 }106 }107 }108 }109}...

Full Screen

Full Screen

Tests.kt

Source:Tests.kt Github

copy

Full Screen

...16class Tests : StringSpec(17 {18 val pluginClasspathResource = ClassLoader.getSystemClassLoader()19 .getResource("plugin-classpath.txt")20 ?: throw IllegalStateException("Did not find plugin classpath resource, run \"testClasses\" build task.")21 val classpath = pluginClasspathResource.openStream().bufferedReader().use { reader ->22 reader.readLines().map { File(it) }23 }24 val scan = ClassGraph()25 .enableAllInfo()26 .acceptPackages(Tests::class.java.`package`.name)27 .scan()28 scan.getResourcesWithLeafName("test.yaml")29 .flatMap {30 log.debug("Found test list in $it")31 val yamlFile = File(it.classpathElementFile.absolutePath + "/" + it.path)32 val testConfiguration = Config {33 addSpec(Root)34 }.from.yaml.inputStream(it.open())35 testConfiguration[Root.tests].map { it to yamlFile.parentFile }36 }37 .forEach { (test, location) ->38 log.debug("Test to be executed: $test from $location")39 val testFolder = folder {40 location.copyRecursively(this.root)41 }42 log.debug("Test has been copied into $testFolder and is ready to get executed")43 test.description {44 val result = GradleRunner.create()45 .withProjectDir(testFolder.root)46 .withPluginClasspath(classpath)47 .withArguments(test.configuration.tasks + test.configuration.options)48 .build()49 println(result.tasks)50 println(result.output)51 test.expectation.output_contains.forEach {52 result.output shouldContain it53 }54 test.expectation.success.forEach {55 result.outcomeOf(it) shouldBe TaskOutcome.SUCCESS56 }57 test.expectation.failure.forEach {58 result.outcomeOf(it) shouldBe TaskOutcome.FAILED59 }60 test.expectation.file_exists.forEach {61 with(File("${testFolder.root.absolutePath}/$it")) {62 shouldExist()...

Full Screen

Full Screen

NetworkResponseAdapterFactoryTest.kt

Source:NetworkResponseAdapterFactoryTest.kt Github

copy

Full Screen

...14 val retrofit = Retrofit.Builder()15 .addCallAdapterFactory(factory)16 .addConverterFactory(StringConverterFactory())17 .baseUrl("http://localhost")18 .build()19 val returnType = typeOf<String>()20 val callAdapter = factory.get(returnType, emptyArray(), retrofit)21 callAdapter shouldBe null22 }23 it("should return null for deferred non-NetworkResponse types") {24 val factory = NetworkResponseAdapterFactory()25 val retrofit = Retrofit.Builder()26 .addCallAdapterFactory(factory)27 .addConverterFactory(StringConverterFactory())28 .baseUrl("http://localhost")29 .build()30 val returnType = typeOf<Deferred<String>>()31 val callAdapter = factory.get(returnType, emptyArray(), retrofit)32 callAdapter shouldBe null33 }34 it("should return null for bare NetworkResponse type") {35 val factory = NetworkResponseAdapterFactory()36 val retrofit = Retrofit.Builder()37 .addCallAdapterFactory(factory)38 .addConverterFactory(StringConverterFactory())39 .baseUrl("http://localhost")40 .build()41 val returnType = typeOf<NetworkResponse<String, String>>()42 val callAdapter = factory.get(returnType, emptyArray(), retrofit)43 callAdapter shouldBe null44 }45 it("should return non-null call adapter for Call<NetworkResponse<...,...>> type") {46 val factory = NetworkResponseAdapterFactory()47 val retrofit = Retrofit.Builder()48 .addCallAdapterFactory(factory)49 .addConverterFactory(StringConverterFactory())50 .baseUrl("http://localhost")51 .build()52 val returnType = typeOf<Call<NetworkResponse<String, String>>>()53 val callAdapter = factory.get(returnType, emptyArray(), retrofit)54 callAdapter shouldNotBe null55 }56 it("suspend return non-null call adapter for Deferred<NetworkResponse<...,...>> type") {57 val factory = NetworkResponseAdapterFactory()58 val retrofit = Retrofit.Builder()59 .addCallAdapterFactory(factory)60 .addConverterFactory(StringConverterFactory())61 .baseUrl("http://localhost")62 .build()63 val returnType = typeOf<Deferred<NetworkResponse<String, String>>>()64 val callAdapter = factory.get(returnType, emptyArray(), retrofit)65 callAdapter shouldNotBe null66 }67 }68})...

Full Screen

Full Screen

DiffSourceFactoryTest.kt

Source:DiffSourceFactoryTest.kt Github

copy

Full Screen

...11 init {12 "diffSourceFactory should return file diff source" {13 // setup14 val filePath = "someFile"15 val diffConfig = buildDiffSourceOption(file = filePath)16 // run17 val diffSource = diffSourceFactory(File("."), diffConfig)18 // assert19 diffSource.shouldBeTypeOf<FileDiffSource>()20 diffSource.sourceDescription shouldBe "File: $filePath"21 }22 "diffSourceFactory should return url diff source" {23 // setup24 val url = "someUrl"25 val diffConfig = buildDiffSourceOption(url = url)26 // run27 val diffSource = diffSourceFactory(File("."), diffConfig)28 // assert29 diffSource.shouldBeTypeOf<UrlDiffSource>()30 diffSource.sourceDescription shouldBe "URL: $url"31 }32 "diffSourceFactory should return git diff source" {33 // setup34 val compareWith = "develop"35 val diffConfig = buildDiffSourceOption(git = compareWith)36 // run37 val diffSource = diffSourceFactory(File("."), diffConfig)38 // assert39 diffSource.shouldBeTypeOf<GitDiffSource>()40 diffSource.sourceDescription shouldBe "Git: diff $compareWith"41 }42 "diffSourceFactory should throw when no source specified" {43 // setup44 val diffConfig = buildDiffSourceOption()45 // run46 val exception = shouldThrow<IllegalStateException> {47 diffSourceFactory(File("."), diffConfig)48 }49 // assert50 exception.message should startWith(51 "Expected Git configuration or file or URL diff source but all are blank"52 )53 }54 "diffSourceFactory should throw when both sources specified" {55 // setup56 val diffConfig = buildDiffSourceOption(file = "file", url = "url", git = "master")57 // run58 val exception = shouldThrow<IllegalStateException> {59 diffSourceFactory(File("."), diffConfig)60 }61 // assert62 exception.message should startWith(63 "Expected only Git configuration or file or URL diff source more than one:"64 )65 }66 }67 private fun buildDiffSourceOption(file: String = "", url: String = "", git: String = ""): DiffSourceConfig {68 return DiffSourceConfig(file, url, git)69 }70}...

Full Screen

Full Screen

MeasurementConverterFactoryTests.kt

Source:MeasurementConverterFactoryTests.kt Github

copy

Full Screen

1package com.github.jvmusin.universalconverter.converter.factory2import com.github.jvmusin.universalconverter.converter.measurementConverterFactory3import com.github.jvmusin.universalconverter.converter.sampleRules4import com.github.jvmusin.universalconverter.fraction.ComplexFraction5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.core.spec.style.BehaviorSpec7import io.kotest.matchers.shouldBe8class MeasurementConverterFactoryTests : BehaviorSpec({9 Given("создание конвертера create") {10 When("правила равны null") {11 Then("бросает MeasurementConverterBuildException") {12 shouldThrow<MeasurementConverterBuildException> {13 measurementConverterFactory.create(null)14 }15 }16 }17 When("среди правил есть null") {18 Then("бросает MeasurementConverterBuildException") {19 shouldThrow<MeasurementConverterBuildException> {20 measurementConverterFactory.create(sampleRules + null)21 }22 }23 }24 When("всё хорошо") {25 Then("создаёт корректный конвертер") {26 val converter = measurementConverterFactory.create(sampleRules)27 val result = converter.convertFractions(28 ComplexFraction(listOf("км"), listOf()),29 ComplexFraction(listOf("м"), listOf())30 )31 result.value shouldBe 100032 }33 }34 }35})...

Full Screen

Full Screen

build

Using AI Code Generation

copy

Full Screen

1class MyTestFactory : FunSpec() {2init {3test("test1") {4}5test("test2") {6}7}8}9class MyTestSpec : FunSpec() {10init {11test("test1") {12}13test("test2") {14}15}16}17class MyTestSpec : FunSpec({18test("test1") {19}20test("test2") {21}22})23class MyTestSpec : FunSpec({24test("test1") {25}26test("test2") {27}28})29class MyTestSpec : FunSpec({30test("test1") {31}32test("test2") {33}34})35class MyTestSpec : FunSpec({36test("test1") {37}38test("test2") {39}40})41class MyTestSpec : FunSpec({42test("test1") {43}44test("test2") {45}46})47class MyTestSpec : FunSpec({48test("test1") {49}50test("test2") {51}52})53class MyTestSpec : FunSpec({54test("test1") {55}56test("test2") {57}58})59class MyTestSpec : FunSpec({60test("test1") {61}62test("test2") {63}64})65class MyTestSpec : FunSpec({66test("test1") {67}68test("test2") {69}70})71class MyTestSpec : FunSpec({72test("test1") {73}74test("test2") {75}76})77class MyTestSpec : FunSpec({78test("test1") {79}80test("test2") {81}82})

Full Screen

Full Screen

build

Using AI Code Generation

copy

Full Screen

1"some spec" {2"some test" {3}4}5}6"some spec" {7"some test" {8}9}10}11"some spec" {12"some test" {13}14}15}16"some spec" {17"some test" {18}19}20}21"some spec" {22"some test" {23}24}25}26"some spec" {27"some test" {28}29}30}31"some spec" {32"some test" {33}34}35}36"some spec" {37"some test" {38}39}40}41"some test" {42}43}

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 build

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful