How to use Tag class of io.kotest.core package

Best Kotest code snippet using io.kotest.core.Tag

BasicsTest.kt

Source:BasicsTest.kt Github

copy

Full Screen

1package micronaut.kotlin.coroutine.sample.coroutine2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.Tag4import io.kotest.core.spec.Spec5import io.kotest.core.spec.style.StringSpec6import io.kotest.core.test.TestCase7import io.kotest.core.test.TestResult8import io.kotest.data.forAll9import io.kotest.data.row10import io.kotest.matchers.shouldBe11import kotlinx.coroutines.ExperimentalCoroutinesApi12import kotlinx.coroutines.delay13import kotlin.math.max14import kotlin.time.ExperimentalTime15import kotlin.time.milliseconds16// タグの定義17// タグは、テスト実行対象を以下のように指定できる。18// gradlew test -Dkotest.tags.include=Linux -Dkotest.tags.exclude=Local19// タグ定義は、異なるパッケージに複数定義してもよい。同一の名称であれば、同じものと判断される。20object Linux : Tag()21object Local : Tag()22/**23 * 基本のテストコード24 *25 * テストクラスは、StringSpec を継承している。26 * Spec には、多数の種類があるが、基本的にはテストケースの記載方法が異なるだけで、できることは同じである。27 * Spec の詳細は、以下を参照。28 * https://github.com/kotest/kotest/blob/3.3.2/doc/styles.md29 */30@ExperimentalTime31@OptIn(ExperimentalCoroutinesApi::class)32class PlainTest : StringSpec({33 // ここで指定した文字列は、テスト結果に出力される。34 // IntelliJ でテストを実行すると、結果表示が文字化けする。35 // ただし、テストレポートファイルは、正常に出力されている。...

Full Screen

Full Screen

build.gradle.kts

Source:build.gradle.kts Github

copy

Full Screen

1import org.jetbrains.kotlin.gradle.tasks.KotlinCompile2group = "org.tormap"3version = "0.0.2"4java.sourceCompatibility = JavaVersion.VERSION_115plugins {6 kotlin("jvm") version "1.6.20"7 kotlin("kapt") version "1.6.20"8 kotlin("plugin.spring") version "1.6.20"9 kotlin("plugin.allopen") version "1.6.20"10 kotlin("plugin.jpa") version "1.6.20"11 // Generate code documentation https://kotlin.github.io/dokka12 id("org.jetbrains.dokka") version "1.6.10"13 // Spring https://spring.io/projects/spring-boot14 id("org.springframework.boot") version "2.6.6"15 id("io.spring.dependency-management") version "1.0.11.RELEASE"16}17repositories {18 mavenCentral()19}20dependencies {21 // Kotlin22 kotlin("reflect")23 kotlin("stdlib-jdk8")24 // Spring Boot https://spring.io/projects/spring-boot25 implementation("org.springframework.boot:spring-boot-starter-web")26 implementation("org.springframework.boot:spring-boot-starter-data-jpa")27 implementation("org.springframework.boot:spring-boot-starter-cache")28 implementation("org.springframework.boot:spring-boot-starter-actuator")29 implementation("org.springframework.boot:spring-boot-starter-security")30 kapt("org.springframework.boot:spring-boot-configuration-processor")31 // OpenAPI generation and Swagger UI https://springdoc.org/32 implementation("org.springdoc:springdoc-openapi-ui:1.6.7")33 implementation("org.springdoc:springdoc-openapi-kotlin:1.6.7")34 // Serialization35 implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.2")36 // Latest stable H2 database driver https://www.h2database.com/37 runtimeOnly("com.h2database:h2:1.4.200")38 // Run Flyway DB migration tool on startup https://flywaydb.org/39 implementation("org.flywaydb:flyway-core:8.5.7")40 // Read .mmdb (MaxMind) DB files for IP lookups https://maxmind.github.io/MaxMind-DB/41 implementation("com.maxmind.geoip2:geoip2:3.0.1")42 // Anaylz user agent https://yauaa.basjes.nl/43 implementation("nl.basjes.parse.useragent:yauaa:6.12")44 // Packages required by metrics-lib (org.torproject.descriptor in java module) (JavaDoc: https://metrics.torproject.org/metrics-lib/index.html)45 implementation("commons-codec:commons-codec:1.10")46 implementation("org.apache.commons:commons-compress:1.13")47 implementation("com.fasterxml.jackson.core:jackson-annotations:2.12.4")48 implementation("com.fasterxml.jackson.core:jackson-databind:2.12.4")49 implementation("com.fasterxml.jackson.core:jackson-core:2.12.4")50 implementation("org.slf4j:slf4j-api:1.7.32")51 implementation("org.tukaani:xz:1.6")52 // Testing & Kotest https://kotest.io/53 testImplementation("org.springframework.boot:spring-boot-starter-test") {54 exclude(group = "org.junit.vintage", module = "junit-vintage-engine")55 }56 testImplementation("io.kotest:kotest-runner-junit5:5.2.3")57 testImplementation("io.kotest:kotest-assertions-core:5.2.3")58 testImplementation("io.kotest.extensions:kotest-extensions-spring:1.1.0")59}60// Fix version requirement from Kotest61extra["kotlin-coroutines.version"] = "1.6.0"62// Allow JPA annotations for Kotlin classes63allOpen {64 annotation("javax.persistence.Entity")65 annotation("javax.persistence.Embeddable")66 annotation("javax.persistence.MappedSuperclass")67}68// Build image for docker https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#build-image69tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootBuildImage> {70 imageName = "juliushenke/tormap"71 tag(version.toString())72 val relativePathIpLookup = "/ip-lookup/"73 bindings = listOf("${rootProject.projectDir.absolutePath}$relativePathIpLookup:/workspace$relativePathIpLookup")74}75// Configure KotlinDoc generation76tasks.dokkaHtml.configure {77 outputDirectory.set(buildDir.resolve("dokka"))78}79// Compile options for JVM build80tasks.withType<KotlinCompile> {81 kotlinOptions {82 freeCompilerArgs = listOf("-Xjsr305=strict")83 jvmTarget = "11"84 }85}86// Configure tests87tasks.withType<Test> {88 useJUnitPlatform()89}...

Full Screen

Full Screen

launcher.kt

Source:launcher.kt Github

copy

Full Screen

1package launcher2import io.kotest.core.TagExpression3import io.kotest.core.descriptors.Descriptor4import io.kotest.core.descriptors.append5import io.kotest.core.descriptors.toDescriptor6import io.kotest.core.filter.TestFilter7import io.kotest.core.filter.TestFilterResult8import io.kotest.core.spec.Spec9import io.kotest.engine.TestEngineLauncher10import io.kotest.engine.listener.TestEngineListener11import io.kotest.framework.discovery.Discovery12import io.kotest.framework.discovery.DiscoveryRequest13import io.kotest.framework.discovery.DiscoveryResult14import io.kotest.framework.discovery.DiscoverySelector15import kotlin.reflect.KClass16/**17 * Creates a [TestEngineLauncher] to be used to launch the test engine.18 */19internal fun setupLauncher(20 args: LauncherArgs,21 listener: TestEngineListener,22): Result<TestEngineLauncher> = runCatching {23 val specClass = args.spec?.let { (Class.forName(it) as Class<Spec>).kotlin }24 val (specs, _, error) = specs(specClass, args.packageName)25 val filter = if (args.testpath == null || specClass == null) null else {26 TestPathTestCaseFilter(args.testpath, specClass)27 }28 if (error != null) throw error29 TestEngineLauncher(listener)30 .withExtensions(listOfNotNull(filter))31 .withTagExpression(args.tagExpression?.let { TagExpression(it) })32 .withClasses(specs)33}34/**35 * Returns the spec classes to execute by using an FQN class name, a package scan,36 * or a full scan.37 */38private fun specs(specClass: KClass<out Spec>?, packageName: String?): DiscoveryResult {39 // if the spec class was null, then we perform discovery to locate all the classes40 // otherwise that specific spec class is used41 return when (specClass) {42 null -> scan(packageName)43 else -> DiscoveryResult(listOf(specClass), emptyList(), null)44 }45}...

Full Screen

Full Screen

RepositoryTest.kt

Source:RepositoryTest.kt Github

copy

Full Screen

...28 .mapNotNull { it.tag }29 .map { semver(testConfiguration.git.tag)(it) } shouldBe expected30 }31 it("should return last version by tag") {32 repo.latestVersionTag()?.simpleTagName shouldBe "v0.4.0"33 }34 it("should return a log of commits after the last version") {35 val commits = repo.log(repo.latestVersionTag())36 assertSoftly {37 commits.size shouldBe 238 commits.first().message.title shouldBe "Commit #6"39 commits.last().message.title shouldBe "Commit #5"40 commits.mapNotNull { it.tag } shouldBe emptyList()41 }42 }43 it("should return full log of commits if untilTag is null") {44 repo.log(untilTag = null) shouldContainExactly repo.log()45 }46 it("should filter commits by predicate") {47 val commits = repo.log { it.title == "Commit #6" }48 assertSoftly {49 commits.size shouldBe 150 commits.first().message.title shouldBe "Commit #6"51 }52 }53 }54 context("last version") {55 it("should return last version - ordered") {56 repo.latestVersionTag()?.simpleTagName shouldBe "v0.4.0"57 }58 it("should return last version - unordered") {59 git().addRelease(3, Semver("3.0.0"))60 git().addRelease(3, Semver("2.0.0"))61 git().addRelease(3, Semver("1.0.0"))62 repo.latestVersionTag()?.simpleTagName shouldBe "v3.0.0"63 }64 }65 }66 }67 override suspend fun beforeSpec(spec: Spec) {68 testConfiguration.git.repo.directory.toFile().deleteRecursively()69 }70 override suspend fun beforeTest(testCase: TestCase) {71 testRepo()72 }73 override suspend fun afterTest(testCase: TestCase, result: TestResult) {74 testConfiguration.git.repo.directory.toFile().deleteRecursively()75 }76}...

Full Screen

Full Screen

ArticleInformationTest.kt

Source:ArticleInformationTest.kt Github

copy

Full Screen

1package com.sierisimo.devto2import com.sierisimo.devto.data.ArticleInformation3import com.sierisimo.devto.data.articleOf4import com.sierisimo.devto.data.requireValidBody5import com.sierisimo.devto.data.requireValidTitle6import io.kotest.assertions.throwables.shouldThrow7import io.kotest.core.spec.style.FunSpec8import io.kotest.core.spec.style.ShouldSpec9import io.kotest.matchers.shouldBe10import io.kotest.property.Arb11import io.kotest.property.arbitrary.filter12import io.kotest.property.arbitrary.list13import io.kotest.property.arbitrary.single14import io.kotest.property.arbitrary.string15import io.kotest.property.forAll16internal class ArticleOfTest : ShouldSpec({17 should("fail when title is empty") {18 shouldThrow<IllegalArgumentException> {19 articleOf(20 title = "",21 markdown = ""22 )23 }24 }25 should("fail when markdown is empty") {26 shouldThrow<IllegalArgumentException> {27 articleOf(28 title = "Test",29 markdown = ""30 )31 }32 }33 should("add corresponding and valid tags as list to the final article") {34 forAll(35 Arb.string(minSize = 1).filter { it.isNotBlank() },36 Arb.string(minSize = 1).filter { it.isNotBlank() },37 Arb.list(Arb.string())38 ) { title, desc, tagList ->39 articleOf(40 title,41 desc,42 tagList43 ) == ArticleInformation(44 title,45 desc,46 tagList.filter { it.isNotBlank() })47 }48 }49})50internal class ArticleInformationTest : FunSpec({51 context("The ArticleInformation") {52 test("fails validation when title is empty") {53 val article =54 ArticleInformation("", Arb.string().single(), emptyList())55 val exception = shouldThrow<IllegalArgumentException> { article.requireValidTitle() }56 exception.message shouldBe "Title cannot be blank or empty for a new article"57 }58 test("fail validation when body is empty") {59 val article =60 ArticleInformation(61 Arb.string(minSize = 1).filter { it.isNotBlank() }.single(), "", emptyList()62 )63 val exception = shouldThrow<IllegalArgumentException> { article.requireValidBody() }64 exception.message shouldBe "Creation of article requires a body in markdown text"65 }66 }67})...

Full Screen

Full Screen

KotestFunSpecStyleTest.kt

Source:KotestFunSpecStyleTest.kt Github

copy

Full Screen

1package com.example.kotest2import com.example.logger3import io.kotest.core.Tag4import io.kotest.core.spec.IsolationMode5import io.kotest.core.spec.style.FunSpec6import org.junit.jupiter.api.fail7class KotestFunSpecStyleTest : FunSpec({8 val logger = logger<KotestFunSpecStyleTest>()9 val list = mutableListOf<String>()10 fun add(item: String) {11 list.add(item)12 }13 add("init")14 logger.info("init, list: {}", list)15 context("context") {16 add("context")17 logger.info("context, list: {}", list)18 test("foo").config(tags = setOf(Tag("foo-test"))) {19 add("foo")20 logger.info("foo, list: {}", list)21 }22 test("fail") {23 add("fail")24 logger.info("fail, list: {}", list)25 fail { "fail, list: $list" }26 }27 test("bar") {28 add("bar")29 logger.info("bar, list: {}", list)30 }31 }32 add("init-2")...

Full Screen

Full Screen

RecipeFilterServiceTest.kt

Source:RecipeFilterServiceTest.kt Github

copy

Full Screen

...14 menu = getFakeMenu()15 filterService = FilterService(menu)16 }17 init {18 "check that getRecipesByTag returns filtered recipes list"{19 val recipesList = filterService.filterRecipeByTag("hot")20 recipesList.size shouldNotBe 021 recipesList.size shouldBeExactly 322 }23 "check that getRecipesByTag returns empty list if recipes not found by tag"{24 val recipesList = filterService.filterRecipeByTag("high-calories")25 recipesList.size shouldBe 026 }27 }28}...

Full Screen

Full Screen

Docker.kt

Source:Docker.kt Github

copy

Full Screen

1package goos2import io.kotest.core.Tag3import io.kotest.core.TagExpression4import io.kotest.core.TagExpression.Companion.Empty5import io.kotest.core.TagExpression.Companion.exclude6import io.kotest.core.extensions.TagExtension7object Docker : Tag()8object DockerTagExtension : TagExtension {9 override fun tags(): TagExpression =10 if (shouldRunDockerTests()) Empty else exclude(Docker)11 private fun shouldRunDockerTests() = !runningAsPartOfBuild()12 private fun runningAsPartOfBuild() = System.getenv("BUILD_SYSTEM") != null13}...

Full Screen

Full Screen

Tag

Using AI Code Generation

copy

Full Screen

1 import io.kotest.core.Tag2 import io.kotest.core.spec.style.FunSpec3 import io.kotest.matchers.shouldBe4 import io.kotest.matchers.string.shouldContain5 import io.kotest.core.test.Description6 import io.kotest.core.test.TestCase7 import io.kotest.core.test.TestResult8 import io.kotest.core.test.TestType9 object SmokeTestTag : Tag()10 class SmokeTest : FunSpec({11 test("test with tag", tags = setOf(SmokeTestTag)) {12 "Hello World".shouldContain("Hello")13 }14 test("test without tag") {15 "Hello World".shouldContain("Hello")16 }17 }) {18 override fun tags() = setOf(SmokeTestTag)19 override suspend fun beforeTest(testCase: TestCase) {20 println("before test")21 }22 override suspend fun afterTest(testCase: TestCase, result: TestResult) {23 println("after test")24 }25 override suspend fun beforeSpec(description: Description) {26 println("before spec")27 }28 override suspend fun afterSpec(description: Description) {29 println("after spec")30 }31 override suspend fun beforeContainer(description: Description) {32 println("before container")33 }34 override suspend fun afterContainer(description: Description) {35 println("after container")36 }37 override suspend fun beforeAny(description: Description) {38 println("before any")39 }40 override suspend fun afterAny(description: Description, result: TestResult) {41 println("after any")42 }43 override suspend fun beforeTest(testCase: TestCase) {44 println("before test")45 }46 override suspend fun afterTest(testCase: TestCase, result: TestResult) {47 println("after test")48 }

Full Screen

Full Screen

Tag

Using AI Code Generation

copy

Full Screen

1val tag = Tag("mytag")2val tag2 = Tag("mytag2")3val tag = Tag("mytag")4val tag2 = Tag("mytag2")5val tag = Tag("mytag")6val tag2 = Tag("mytag2")7val tag = Tag("mytag")8val tag2 = Tag("mytag2")9val tag = Tag("mytag")10val tag2 = Tag("mytag2")11val tag = Tag("mytag")12val tag2 = Tag("mytag2")13val tag = Tag("mytag")14val tag2 = Tag("mytag2")15val tag = Tag("mytag")16val tag2 = Tag("mytag2")17val tag = Tag("mytag")18val tag2 = Tag("mytag2")19val tag = Tag("mytag")20val tag2 = Tag("mytag2")21val tag = Tag("mytag")22val tag2 = Tag("mytag2")23val tag = Tag("mytag")24val tag2 = Tag("mytag2")25val tag = Tag("mytag")26val tag2 = Tag("mytag2")27val tag = Tag("mytag")28val tag2 = Tag("mytag2")29val tag = Tag("mytag")30val tag2 = Tag("mytag2")31val tag = Tag("mytag")32val tag2 = Tag("mytag2")

Full Screen

Full Screen

Tag

Using AI Code Generation

copy

Full Screen

1import io.kotest.core.spec.style.DescribeSpec2import io.kotest.matchers.shouldBe3class TagExample : DescribeSpec() {4 init {5 describe("some test") {6 it("some test").config(tags = setOf(Tag("slow"))) {7 }8 }9 }10}11import io.kotest.core.spec.style.DescribeSpec12import io.kotest.core.tags.Tag13import io.kotest.matchers.shouldBe14class TagExample : DescribeSpec() {15 init {16 describe("some test") {17 it("some test").config(tags = setOf(Tag("slow"))) {18 }19 }20 }21}22import io.kotest.core.spec.style.DescribeSpec23import io.kotest.matchers.shouldBe24class TagExample : DescribeSpec() {25 init {26 describe("some test") {27 it("some test").config(tags = setOf(Tag("slow"))) {28 }29 }30 }31}32import io.kotest.core.spec.style.DescribeSpec33import io.kotest.core.tags.Tag34import io.kotest.matchers.shouldBe35class TagExample : DescribeSpec() {36 init {37 describe("some test") {38 it("some test").config(tags = setOf(Tag("slow"))) {39 }40 }41 }42}43import io.kotest.core.spec.style.DescribeSpec44import io.kotest.matchers.shouldBe45class TagExample : DescribeSpec() {46 init {47 describe("some test") {48 it("some test").config(tags = setOf(Tag("slow"))) {49 }50 }51 }52}53import io.kotest.core.spec.style.DescribeSpec54import io.kotest.core.tags.Tag55import io.kotest.matchers.shouldBe

Full Screen

Full Screen

Tag

Using AI Code Generation

copy

Full Screen

1 import io.kotest.core.spec.style.FunSpec2 import io.kotest.matchers.shouldBe3 class TagExampleTest : FunSpec({4 test("test one") {5 }.config(tags = setOf(Tag("mytag")))6 test("test two") {7 }.config(tags = setOf(Tag("mytag"), Tag("myothertag")))8 })

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 Tag

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful