How to use Int.shouldBePositive method of io.kotest.matchers.ints.int class

Best Kotest code snippet using io.kotest.matchers.ints.int.Int.shouldBePositive

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106 describe("general") {107 it("basics") {108 (1 == 1).shouldBeTrue()109 (2 + 2) shouldBe 4110 val foo: Any = "foobar"111 foo.shouldBeTypeOf<String>() shouldContain "fo"112 "".shouldBeEmpty()113 "x".shouldNot(beEmpty()) // manually negate114 "x".shouldNotBeEmpty() // reusable115 URI("https://tba") shouldHaveHost "tba"116 URI("https://tba:81") shouldHavePort 81117 URI("https://tba") shouldHaveScheme "https"118 File("/").apply {119 shouldExist()120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1199 listOf(1).shouldBeSingleton {200 it.shouldBeOdd()201 }202 listOf(1).shouldHaveSingleElement {203 beOdd().test(it).passed() // have to return a boolean here :-/204 }205 listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206 listOf(1) shouldBeSmallerThan listOf(1, 2)207 listOf(1) shouldBeSameSizeAs listOf(2)208 listOf(1, 2) shouldHaveAtLeastSize 1209 listOf(1, 2).shouldBeSorted()210 mapOf(1 to "a").shouldContain(1, "a") // at least this211 mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212 mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213 mapOf(1 to "a") shouldContainKey 1214 emptyMap<Any, Any>().shouldBeEmpty()215 }216 it("exceptions") {217 class SubException() : Exception()218 Exception("a") shouldHaveMessage "a" // same (not contains!)219 Exception("abc").message shouldContain "b"220 Exception("", Exception()).shouldHaveCause()221 Exception("symptom", Exception("cause")).shouldHaveCause {222 it.message shouldBe "cause"223 }224 Exception("", SubException()).shouldHaveCauseInstanceOf<Exception>() // T or subclass225 Exception("", SubException()).shouldHaveCauseOfType<SubException>() // exactly T226 shouldThrow<Exception> { // type or subtype227 throw SubException()228 }229 shouldThrowExactly<Exception> { // exactly that type (no subtype!)230 throw Exception()231 }232 shouldThrowAny { // don't care which233 throw Exception()234 }235 }236 }237 describe("advanced") {238 it("selective matcheres") {239 data class Foo(val p1: Int, val p2: Int)240 val foo1 = Foo(1, 1)241 val foo2 = Foo(1, 2)242 foo1.shouldBeEqualToUsingFields(foo2, Foo::p1)243 foo1.shouldBeEqualToIgnoringFields(foo2, Foo::p2)244 class Bar(val p1: Int, val p2: Int) // not a data class! no equals.245 val bar1a = Bar(1, 1)246 val bar1b = Bar(1, 1)247 bar1a shouldNotBe bar1b248 bar1a shouldBeEqualToComparingFields bar1b // "fake equals" (ignoring private properties)249 bar1a.shouldBeEqualToComparingFields(bar1b, false) // explicitly also check private props250 val bar2 = Bar(1, 2)251 bar1a.shouldBeEqualToComparingFieldsExcept(bar2, Bar::p2)252 }253 }254 // channels255 // concurrent, futures256 // result, optional257 // threads258 // reflection259 // statistic, regex260})261private data class SomeType(val value: Int = 1)262private annotation class Connotation...

Full Screen

Full Screen

AssertSoftlyTest.kt

Source:AssertSoftlyTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.assertions.withClue5import io.kotest.core.spec.style.FreeSpec6import io.kotest.matchers.collections.containExactly7import io.kotest.matchers.comparables.beLessThan8import io.kotest.matchers.doubles.negative9import io.kotest.matchers.doubles.positive10import io.kotest.matchers.doubles.shouldBeNegative11import io.kotest.matchers.ints.shouldBeLessThan12import io.kotest.matchers.ints.shouldBePositive13import io.kotest.matchers.maps.haveKey14import io.kotest.matchers.should15import io.kotest.matchers.shouldBe16import io.kotest.matchers.shouldNot17import io.kotest.matchers.shouldNotBe18import io.kotest.matchers.string.contain19import io.kotest.matchers.string.endWith20import io.kotest.matchers.string.shouldContain21import io.kotest.matchers.string.shouldNotContain22import io.kotest.matchers.string.shouldNotEndWith23import io.kotest.matchers.string.shouldStartWith24class AssertSoftlyTest : FreeSpec({25 "assertSoftly" - {26 "passes when all assertions pass" {27 assertSoftly {28 1 shouldBe 129 "foo" shouldBe "foo"30 }31 }32 "rethrows single failures" {33 val exception = shouldThrow<AssertionError> {34 assertSoftly {35 1 shouldBe 236 }37 }38 exception.message shouldBe "expected:<2> but was:<1>"39 exception.stackTrace.first().className shouldStartWith "com.sksamuel.kotest.matchers.AssertSoftlyTest"40 }41 "groups multiple failures" {42 shouldThrow<AssertionError> {43 assertSoftly {44 1 shouldBe 245 1 shouldBe 1 // should pass46 "foo" shouldNotBe "foo"47 }48 }.let {49 it.message should contain("1) expected:<2> but was:<1>")50 it.message should contain("2) \"foo\" should not equal \"foo\"")51 it.stackTrace.first().className shouldStartWith "com.sksamuel.kotest.matchers.AssertSoftlyTest"52 }53 }54 "works with all array types" {55 shouldThrow<AssertionError> {56 assertSoftly {57 booleanArrayOf(true) shouldBe booleanArrayOf(false)58 intArrayOf(1) shouldBe intArrayOf(2)59 shortArrayOf(1) shouldBe shortArrayOf(2)60 floatArrayOf(1f) shouldBe floatArrayOf(2f)61 doubleArrayOf(1.0) shouldBe doubleArrayOf(2.0)62 longArrayOf(1) shouldBe longArrayOf(2)63 byteArrayOf(1) shouldBe byteArrayOf(2)64 charArrayOf('a') shouldBe charArrayOf('b')65 arrayOf("foo") shouldBe arrayOf("bar")66 }67 }.let {68 it.message should contain("1) expected:<[false]> but was:<[true]>")69 it.message should contain("2) expected:<[2]> but was:<[1]>")70 it.message should contain("3) expected:<[2]> but was:<[1]>")71 it.message should contain("4) expected:<[2.0f]> but was:<[1.0f]>")72 it.message should contain("5) expected:<[2.0]> but was:<[1.0]>")73 it.message should contain("6) expected:<[2L]> but was:<[1L]>")74 it.message should contain("7) expected:<[2]> but was:<[1]>")75 it.message should contain("8) expected:<['b']> but was:<['a']>")76 it.message should contain("""9) Element differ at index: [0]77 |expected:<["bar"]> but was:<["foo"]>""".trimMargin())78 it.message shouldNot contain("10) ")79 }80 }81 "works with any matcher" {82 shouldThrow<AssertionError> {83 assertSoftly {84 1 should beLessThan(0)85 "foobar" shouldNot endWith("bar")86 1 shouldBe positive() // should pass87 1.0 shouldBe negative()88 listOf(1) shouldNot containExactly(1)89 mapOf(1 to 2) should haveKey(3)90 }91 }.let {92 it.message should contain("5) Map should contain key 3")93 it.message shouldNot contain("6) ")94 }95 }96 "works with extension functions" {97 shouldThrow<AssertionError> {98 assertSoftly {99 1.shouldBeLessThan(0)100 "foobar".shouldNotEndWith("bar")101 1.shouldBePositive() // should pass102 1.0.shouldBeNegative()103 }104 }.let {105 it.message should contain("""1) 1 should be < 0""")106 it.message should contain("""2) "foobar" should not end with "bar"""")107 it.message should contain("""3) 1.0 should be < 0.0""")108 it.message shouldNot contain("4) ")109 }110 }111 "can be nested" {112 shouldThrow<AssertionError> {113 assertSoftly {114 1 shouldBe 2115 assertSoftly {116 2 shouldBe 3117 }118 }119 }.let {120 it.message should contain("1) expected:<2> but was:<1>")121 it.message should contain("2) expected:<3> but was:<2>")122 }123 }124 "should not have any receiver context" {125 data class Person(val name: String, val age: Int)126 fun verifier(person: Person, assertion: (Person) -> Unit) {127 assertion(person)128 }129 val person = Person("foo", 0)130 verifier(person) {131 it shouldBe person132 assertSoftly {133 it shouldBe person // it being person verifies assertSoftly does not have any receiver134 }135 }136 }137 "Receiver version" - {138 "works on a receiver object" {139 shouldThrow<AssertionError> {140 assertSoftly("foo") {141 length shouldBe 2142 this[1] shouldBe 'o' // should pass143 this shouldNotBe "foo"144 }145 }.let {146 it.message should contain("1) expected:<2> but was:<3>")147 it.message should contain("2) \"foo\" should not equal \"foo\"")148 }149 }150 "Returns the receiver" {151 val a = assertSoftly("foo") {152 this shouldNotBe "bar"153 shouldNotEndWith("abc")154 }155 a shouldBe "foo"156 }157 "works with 'it' receiver" {158 val a = assertSoftly("foo") {159 it shouldNotBe "bar"160 }161 a shouldBe "foo"162 }163 "works with my parameter name" {164 val a =165 assertSoftly("foo") { foo -> // No idea why anybody would use this, but it's better to keep the verification that this works166 foo shouldNotBe "bar"167 }168 a shouldBe "foo"169 }170 }171 "Assert softly with data classes" - {172 // Added as a verification of https://github.com/kotest/kotest/issues/1831173 "work with enum in data class" {174 val source = WithSimpleEnum(enumValue = SimpleEnum.First)175 val result = WithSimpleEnum(enumValue = SimpleEnum.Second)176 val error = shouldThrow<AssertionError> {177 assertSoftly {178 withClue("simple strings") {179 "a" shouldBe "b"180 "a" shouldNotBe "b"181 }182 withClue("more complex with data class and enums") {183 source shouldBe result184 source shouldNotBe result185 }186 }187 }188 error.message shouldContain "1) simple strings\n" +189 "expected:<\"b\"> but was:<\"a\">"190 error.message shouldContain "2) data class diff for com.sksamuel.kotest.matchers.WithSimpleEnum\n" +191 "└ enumValue: more complex with data class and enums\n" +192 "expected:<Second> but was:<First>"193 error.message shouldNotContain "3) "194 }195 }196 }197})198enum class SimpleEnum {199 First,200 Second201}202data class WithSimpleEnum(val enumValue: SimpleEnum = SimpleEnum.First)...

Full Screen

Full Screen

IntMatchersTest.kt

Source:IntMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.numerics2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.matchers.ints.beEven4import io.kotest.matchers.ints.beOdd5import io.kotest.matchers.ints.shouldBeBetween6import io.kotest.matchers.ints.shouldBeGreaterThan7import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual8import io.kotest.matchers.ints.shouldBeLessThan9import io.kotest.matchers.ints.shouldBeLessThanOrEqual10import io.kotest.matchers.ints.shouldBeNegative11import io.kotest.matchers.ints.shouldBePositive12import io.kotest.matchers.ints.shouldBeZero13import io.kotest.matchers.ints.shouldNotBeZero14import io.kotest.core.spec.style.StringSpec15import io.kotest.matchers.should16import io.kotest.matchers.shouldBe17import io.kotest.matchers.shouldNot18import io.kotest.matchers.shouldNotBe19import io.kotest.data.forAll20import io.kotest.data.forNone21import io.kotest.data.headers22import io.kotest.data.row23import io.kotest.data.table24class IntMatchersTest : StringSpec() {25 init {26 "be positive" {27 1.shouldBePositive()28 shouldThrow<AssertionError> {29 (-1).shouldBePositive()30 }.message shouldBe "-1 should be > 0"31 shouldThrow<AssertionError> {32 (0).shouldBePositive()33 }.message shouldBe "0 should be > 0"34 }35 "be negative" {36 (-1).shouldBeNegative()37 shouldThrow<AssertionError> {38 1.shouldBeNegative()39 }.message shouldBe "1 should be < 0"40 shouldThrow<AssertionError> {41 0.shouldBeNegative()42 }.message shouldBe "0 should be < 0"43 }44 "should return expected/actual in intellij format" {45 shouldThrow<AssertionError> {46 1 shouldBe 44447 }.message shouldBe "expected:<444> but was:<1>"48 }49 "shouldBe should support ints" {50 1 shouldBe 151 }52 "isEven" {53 4 shouldBe beEven()54 3 shouldNotBe beEven()55 }56 "isOdd" {57 3 shouldBe beOdd()58 4 shouldNotBe beOdd()59 }60 "inRange" {61 3 should io.kotest.matchers.ints.beInRange(1..10)62 3 should io.kotest.matchers.ints.beInRange(3..10)63 3 should io.kotest.matchers.ints.beInRange(3..3)64 4 shouldNot io.kotest.matchers.ints.beInRange(3..3)65 4 shouldNot io.kotest.matchers.ints.beInRange(1..3)66 }67 "beGreaterThan" {68 1 should io.kotest.matchers.ints.beGreaterThan(0)69 3.shouldBeGreaterThan(2)70 shouldThrow<AssertionError> {71 2 should io.kotest.matchers.ints.beGreaterThan(3)72 }73 }74 "beLessThan" {75 1 should io.kotest.matchers.ints.beLessThan(2)76 1.shouldBeLessThan(2)77 shouldThrow<AssertionError> {78 2 shouldBe io.kotest.matchers.ints.lt(1)79 }80 }81 "beLessThanOrEqualTo" {82 1 should io.kotest.matchers.ints.beLessThanOrEqualTo(2)83 2.shouldBeLessThanOrEqual(3)84 shouldThrow<AssertionError> {85 2 shouldBe io.kotest.matchers.ints.lte(1)86 }87 }88 "beGreaterThanOrEqualTo" {89 1 should io.kotest.matchers.ints.beGreaterThanOrEqualTo(0)90 3.shouldBeGreaterThanOrEqual(1)91 shouldThrow<AssertionError> {92 2 should io.kotest.matchers.ints.beGreaterThanOrEqualTo(3)93 }94 }95 "between should test for valid interval" {96 val table = table(97 headers("a", "b"),98 row(0, 2),99 row(1, 2),100 row(0, 1),101 row(1, 1)102 )103 forAll(table) { a, b ->104 1 shouldBe io.kotest.matchers.ints.between(a, b)105 1.shouldBeBetween(a, b)106 }107 }108 "between should test for invalid interval" {109 val table = table(110 headers("a", "b"),111 row(0, 2),112 row(2, 2),113 row(4, 5),114 row(4, 6)115 )116 forNone(table) { a, b ->117 3 shouldBe io.kotest.matchers.ints.between(a, b)118 }119 }120 "shouldBeZero" {121 0.shouldBeZero()122 1.shouldNotBeZero()123 Int.MIN_VALUE.shouldNotBeZero()124 Int.MAX_VALUE.shouldNotBeZero()125 }126 }127}...

Full Screen

Full Screen

EmployeeSpec.kt

Source:EmployeeSpec.kt Github

copy

Full Screen

1package ru.iopump.qa.sample.spec2import com.github.tomakehurst.wiremock.client.WireMock3import io.kotest.assertions.asClue4import io.kotest.core.config.ExperimentalKotest5import io.kotest.core.spec.style.FreeSpec6import io.kotest.matchers.ints.shouldBePositive7import io.kotest.matchers.nulls.shouldNotBeNull8import io.kotest.matchers.shouldBe9import io.kotest.property.Arb10import io.kotest.property.arbitrary.next11import io.kotest.property.arbitrary.positiveInts12import io.kotest.property.arbitrary.stringPattern13import io.qameta.allure.Epic14import io.qameta.allure.Feature15import io.qameta.allure.Link16import io.qameta.allure.Story17import okhttp3.Credentials18import retrofit2.Response19import retrofit2.awaitResponse20import ru.iopump.qa.sample.RegistryAndProjectConfiguration.employeeService21import ru.iopump.qa.sample.RegistryAndProjectConfiguration.wiremockClient22import ru.iopump.qa.sample.model.Employee23@ExperimentalKotest24@Epic("Tproger example")25@Feature("Employee endpoint")26@Story("CRUD")27@Link("tproger.ru", url = "https://tproger.ru/")28class EmployeeSpec : FreeSpec() {29 override fun concurrency(): Int = 230 init {31 "Scenario: Getting employee by id" - {32 var expectedId = 033 "Given test environment is up and test data prepared" {34 expectedId = Arb.positiveInts().next()35 }36 lateinit var response: Response<Employee>37 "When client sent request to get the employee by id=$expectedId" {38 response = employeeService.get(expectedId).awaitResponse()39 }40 "Then client received response with status 200 and id=$expectedId" {41 response.asClue {42 it.code() shouldBe 20043 it.body().shouldNotBeNull().asClue { employee ->44 employee.name shouldBe "Max"45 employee.id shouldBe expectedId46 }47 }48 }49 }50 "Scenario: Creating new employee" - {51 lateinit var employee: Employee52 "Given test environment is up and test data prepared" {53 employee = Employee(54 name = Arb.stringPattern("[A-Z]{1}[a-z]{5,10}").next()55 )56 }57 lateinit var response: Response<Employee>58 val basic = Credentials.basic("user", "user")59 "When client sent request to create new $employee" {60 response = employeeService.create(basic, employee).awaitResponse()61 }62 "Then server received request with $employee" {63 wiremockClient.verifyThat(64 1,65 WireMock.postRequestedFor(WireMock.urlPathEqualTo("/employee"))66 .withHeader("Authorization", WireMock.equalTo(basic))67 )68 }69 "And client received response with status 200 with generated id" {70 response.asClue {71 it.code() shouldBe 20072 it.body().shouldNotBeNull().asClue { e ->73 e.name shouldBe employee.name74 e.id.shouldNotBeNull().shouldBePositive()75 }76 }77 }78 }79 }80}...

Full Screen

Full Screen

IntTest.kt

Source:IntTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.property.arbitrary2import io.kotest.core.spec.style.FunSpec3import io.kotest.data.blocking.forAll4import io.kotest.data.row5import io.kotest.inspectors.forAll6import io.kotest.matchers.ints.*7import io.kotest.matchers.shouldBe8import io.kotest.property.Arb9import io.kotest.property.PropTest10import io.kotest.property.arbitrary.*11import io.kotest.property.checkAll12import io.kotest.property.checkCoverage13class IntTest : FunSpec({14 test("<Int, Int> should give values between min and max inclusive") {15 // Test parameters include the test for negative bounds16 forAll(17 row(-10, -1),18 row(1, 3),19 row(-100, 100),20 row(Int.MAX_VALUE - 10, Int.MAX_VALUE),21 row(Int.MIN_VALUE, Int.MIN_VALUE + 10)22 ) { vMin, vMax ->23 val expectedValues = (vMin..vMax).toSet()24 val actualValues = (1..100_000).map { Arb.int(vMin, vMax).single() }.toSet()25 actualValues shouldBe expectedValues26 }27 }28 test("Arb.int edge cases should respect min and max bounds") {29 checkCoverage("run", 25.0) {30 PropTest(iterations = 1000).checkAll<Int, Int> { min, max ->31 if (min < max) {32 classify("run")33 Arb.int(min..max).edgecases().forAll {34 it.shouldBeBetween(min, max)35 }36 }37 }38 }39 }40 test("Arb.positiveInts should return positive ints only") {41 val numbers = Arb.positiveInt().take(1000).toSet()42 numbers.forAll { it.shouldBePositive() }43 }44 test("Arb.nonNegativeInts should return non negative ints only") {45 val numbers = Arb.nonNegativeInt().take(1000).toSet()46 numbers.forAll { it.shouldBeNonNegative() }47 }48 test("Arb.negativeInts should return negative ints only") {49 val numbers = Arb.negativeInt().take(1000).toSet()50 numbers.forAll { it.shouldBeNegative() }51 }52 test("Arb.nonPositiveInts should return non positive ints only") {53 val numbers = Arb.nonPositiveInt().take(1000).toSet()54 numbers.forAll { it.shouldBeNonPositive() }55 }56})57class UIntTest : FunSpec({58 test("<UInt, UInt> should give values between min and max inclusive") {59 forAll(60 row(1u, 3u),61 row(0u, 100u),62 row(UInt.MAX_VALUE - 10u, UInt.MAX_VALUE),63 row(UInt.MIN_VALUE, UInt.MIN_VALUE + 10u)64 ) { vMin, vMax ->65 val expectedValues = (vMin..vMax).toSet()66 val actualValues = (1..100_000).map { Arb.uInt(vMin, vMax).single() }.toSet()67 actualValues shouldBe expectedValues68 }69 }70 test("Arb.uInt edge cases should respect min and max bounds") {71 checkCoverage("run", 25.0) {72 PropTest(iterations = 1000).checkAll<UInt, UInt> { min, max ->73 if (min < max) {74 classify("run")75 Arb.uInt(min..max).edgecases().forAll {76 it.shouldBeBetween(min, max)77 }78 }79 }80 }81 }82})...

Full Screen

Full Screen

int.kt

Source:int.kt Github

copy

Full Screen

1package io.kotest.matchers.ints2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.comparables.gt5import io.kotest.matchers.comparables.gte6import io.kotest.matchers.comparables.lt7import io.kotest.matchers.comparables.lte8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNot11import io.kotest.matchers.shouldNotBe12fun Int.shouldBePositive() = this shouldBe positive()13fun positive() = object : Matcher<Int> {14 override fun test(value: Int) = MatcherResult(value > 0, "$value should be > 0", "$value should not be > 0")15}16fun Int.shouldBeNegative() = this shouldBe negative()17fun negative() = object : Matcher<Int> {18 override fun test(value: Int) = MatcherResult(value < 0, "$value should be < 0", "$value should not be < 0")19}20fun Int.shouldBeEven() = this should beEven()21fun Int.shouldNotBeEven() = this shouldNot beEven()22fun beEven() = object : Matcher<Int> {23 override fun test(value: Int): MatcherResult =24 MatcherResult(value % 2 == 0, "$value should be even", "$value should be odd")25}26fun Int.shouldBeOdd() = this should beOdd()27fun Int.shouldNotBeOdd() = this shouldNot beOdd()28fun beOdd() = object : Matcher<Int> {29 override fun test(value: Int): MatcherResult =30 MatcherResult(value % 2 == 1, "$value should be odd", "$value should be even")31}32infix fun Int.shouldBeLessThan(x: Int) = this shouldBe lt(x)33infix fun Int.shouldNotBeLessThan(x: Int) = this shouldNotBe lt(x)34infix fun Int.shouldBeLessThanOrEqual(x: Int) = this shouldBe lte(x)35infix fun Int.shouldNotBeLessThanOrEqual(x: Int) = this shouldNotBe lte(x)36infix fun Int.shouldBeGreaterThan(x: Int) = this shouldBe gt(x)37infix fun Int.shouldNotBeGreaterThan(x: Int) = this shouldNotBe gt(x)38infix fun Int.shouldBeGreaterThanOrEqual(x: Int) = this shouldBe gte(x)39infix fun Int.shouldNotBeGreaterThanOrEqual(x: Int) = this shouldNotBe gte(x)40infix fun Int.shouldBeExactly(x: Int) = this shouldBe exactly(x)41infix fun Int.shouldNotBeExactly(x: Int) = this shouldNotBe exactly(x)42fun Int.shouldBeZero() = this shouldBeExactly 043fun Int.shouldNotBeZero() = this shouldNotBeExactly 0...

Full Screen

Full Screen

Int.shouldBePositive

Using AI Code Generation

copy

Full Screen

1x.shouldBePositive()2x.shouldBeNegative()3x.shouldBeLessThan(y)4x.shouldBeLessThanOrEqual(y)5x.shouldBeGreaterThan(y)6x.shouldBeGreaterThanOrEqual(y)7x.shouldBeBetween(y, z)8x.shouldBeBetweenClosed(y, z)9x.shouldBeBetweenInclusive(y, z)10x.shouldBeBetweenInclusiveClosed(y, z)11x.shouldBeBetweenExclusive(y, z)

Full Screen

Full Screen

Int.shouldBePositive

Using AI Code Generation

copy

Full Screen

1Int.shouldBePositive(1)2String.shouldBeEmpty("")3Int.shouldBePositive(1)4String.shouldBeEmpty("")5Int.shouldBePositive(1)6String.shouldBeEmpty("")7Int.shouldBePositive(1)8String.shouldBeEmpty("")9Int.shouldBePositive(1)10String.shouldBeEmpty("")11Int.shouldBePositive(1)12String.shouldBeEmpty("")13Int.shouldBePositive(1)14String.shouldBeEmpty("")15Int.shouldBePositive(1)16String.shouldBeEmpty("")17Int.shouldBePositive(1)18String.shouldBeEmpty("")19Int.shouldBePositive(1)

Full Screen

Full Screen

Int.shouldBePositive

Using AI Code Generation

copy

Full Screen

1@DisplayName("Int Test")2class IntTest {3fun `Int should be positive`() {4num.shouldBePositive()5}6}7@DisplayName("String Test")8class StringTest {9fun `String should be equal ignoring case`() {10str.shouldBeEqualIgnoringCase("hello")11}12}13@DisplayName("String Test")14class StringTest {15fun `String should start with`() {16str.shouldStartWith("He")17}18}19@DisplayName("String Test")20class StringTest {21fun `String should end with`() {22str.shouldEndWith("lo")23}24}25@DisplayName("String Test")26class StringTest {27fun `String should contain`() {28str.shouldContain("ll")29}30}31@DisplayName("String Test")32class StringTest {33fun `String should be blank`() {34str.shouldBeBlank()35}36}37@DisplayName("String Test")38class StringTest {39fun `String should be empty`() {40str.shouldBeEmpty()41}42}43@DisplayName("String Test")44class StringTest {45fun `String should be equal`() {46str.shouldBeEqual("Hello")47}48}49@DisplayName("String Test")50class StringTest {51fun `String should be equal ignoring case`() {52str.shouldBeEqualIgnoringCase("hello")53}54}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful