computer_study

[kotest] Core Matchers 기록 본문

개발 참고자료/kotlin

[kotest] Core Matchers 기록

knowable 2022. 8. 2. 17:18

kotest core matchers

범용

  • obj.shouldBe(other) : 주어진 obj와 other가 모두 같다는 범용 assertion
  • expr.shouldBeTrue() : 표현식이 true인지 확인
  • expr.shouldBeFalse() : 표현식이 false인지 확인
  • shouldThrow <T> { block } : 블록이 T Throwable 또는 하위 유형을 throw 하는지 확인
  • shouldThrowExactly <T> { block } : 블록이 정확히 예외를 throw 하는지 확인
  • shouldThrowAny { block } : 블록이 모든 유형의 throwable을 throw하는지 확인
  • shouldThrowMessage(message) { block } : 코드 블록이 주어진 메시지와 함께 모든 throwable을 throw하는지 확인

타입

  • obj.shouldBeSameInstanceAs(other) : 개체를 ID로 비교하여 정확히 동일한 참조인지 확인
  • obj.shouldBeTypeOf <T>() : 주어진 Type이 정확히 T 유형이라고 확인, 하위 클래스는 실패한다
  • obj.shouldBeInstanceOf <T> : 주어진 참조가 T 유형 또는 T의 하위 클래스임을 확인
  • obj.shouldHaveAnnotation(annotationClass) : 주어진 인스턴스에 에 지정된 유형의 Annotation이 있는지 확인
  • obj.shouldBeNull() : 지정된 참조가 null임을 확인

비교

  • comp.shouldBeLessThan(other) : compareTo를 사용하여 comp가 other보다 미만인지 확인
  • comp.shouldBeLessThanOrEqualTo(other) : compareTo를 사용하여 comp가 other보다 작거나 같은지 확인
  • comp.shouldBeEqualComparingTo(other) : compareTo를 사용하여 comp가 other보다 같은지 확인
  • comp.shouldBeEqualComparingTo(other, comparator) : comparator.compare를 사용하여 comp와 other이 같은지 확인
  • comp.shouldBeGreaterThan(other) : compareTo를 사용하여 comp가 other보다 큰지 확인
  • comp.shouldBeGreaterThanOrEqualTo(other) : compareTo를 사용하여 comp가 other보다 크거나 같은지 확인

Iterator

  • iterator.shouldBeEmpty() : iterator에 다음 값이 없는지 검증
  • iterator.shouldHaveNext() : iterator에 다음값이 있는지 검증

Map

  • map.shouldContain("key", "value") : map에 "key"에 대해 매핑되는 "value"가 있는지 확인
  • map.shouldContainAll(other) : map과 other이 동일한 쌍을 포함하는지 확인
  • map.shouldContainExactly(other) : map과 other이 정확하게 동일한 쌍을 포함하는지(다른 쌍은 없어야 함) 확인
  • map.shouldContainKey(key) : map에 "key"의 값이 포함되어있는지 확인
  • map.shouldContainKeys(keys) : map에 주어진 "keys"에 모든 값이 매핑되어있는지 확인
  • map.shouldContainValue(value) : map에 주어진 "value"가 하나 이상 매핑되어있는지 확인
  • map.shouldContainValues(values) : map에 주어진 "values"가 모두 포함하고 있는지 확인
  • map.shouldBeEmpty() : map이 비어있는지 확인

String

  • str.shouldBeBlank() : 문자열이 nullOrEmpty인지 확인
  • str.shouldBeEmpty() : 문자열의 길이가 0 임을 확인
  • str.shouldBeLowerCase() : 문자열이 모두 소문자인지 확인
  • str.shouldBeUpperCase() : 문자열이 모두 대문자임을 확인
  • str.shouldContain("substr") : 문자열에 지정된 하위 문자열이 포함되어 있는지 확인. 하위 문자열은 문자열과 같을 수 있고, 대 소문자를 구분한다
  • str.shouldContain(regex) : 문자열에 주어진 정규 표현식이 포함되어 있는지 확인
  • str.shouldContainADigit() : 문자열에 최소한 하나의 숫자가 포함되어 있는지 확인
  • str.shouldContainIgnoringCase(substring) : 문자열에 대소문자를 무시하고 하위 문자열이 포함되어 있는지 확인
  • str.shouldContainOnlyDigits() : 문자열에 숫자만 포함되어 있거나 비어 있는지 확인
  • str.shouldBeInteger([radix]) : 문자열에 정수가 포함되어 있는지 확인하고 반환
  • str.shouldContainOnlyOnce(substring) : 문자열에 부분 문자열이 정확히 한 번 포함되어 있는지 확인
  • str.shouldEndWith("suffix") : 문자열이 지정된 접미사로 끝나는 것을 확인. 접미사는 문자열과 같을 수 있고, 대소문자를 구분한다
  • str.shouldHaveLength(length) : 문자열이 주어진 길이를 가지고 있는지 확인
    str.shouldHaveLineCount(count) : 문자열에 주어진 수의 행이 포함되어 있는지 확인. tr.split("\n"). length.shouldBe(n)
  • str.shouldHaveMaxLength(max) : 문자열이 주어진 최대 길이보다 길지 않은지 확인
  • str.shouldHaveMinLength(min) : 문자열이 주어진 최소 길이보다 짧지 않은지 확인
  • str.shouldHaveSameLengthAs(length) : 문자열의 길이가 다른 문자열과 동일한지 확인
  • str.shouldMatch(regex) : 문자열이 주어진 정규식과 완전히 일치하는지 확인
  • str.shouldStartWith("prefix") : 문자열이 주어진 접두사로 시작하는지 확인. 접두사는 문자열과 같을 수 있고, 대소문자를 구분한다
  • str.shouldBeEqualIgnoringCase(other) : 문자열이 대소문자를 무시하고 다른 문자열과 같은지 확인

Integer, Long

  • num.shouldBeBetween(x, y) : x와 y 사이에 있고 x와 y를 모두 포함하는지 확인
  • num.shouldBeLessThan(n) : num이 주어진 값 n보다 작다고 주장
  • num.shouldBeLessThanOrEqual(n): num이 주어진 값 n보다 작거나 같은지 확인
  • num.shouldBeGreaterThan(n) : num이 주어진 값 n보다 큰지 확인
  • num.shouldBeGreaterThanOrEqual(n) : num이 주어진 값 n보다 크거나 같은지 확인
  • num.shouldBeEven() : num이 짝수 임인지 확인
  • num.shouldBeOdd() : num이 홀수임을 확인
  • num.shouldBeInRange(range) : num이 지정된 범위에 포함되어 있는지 확인
  • num.shouldBeZero() : num이 0 임을 확인

Collection

  • collection.shouldBeEmpty() : 컬렉션에 element가 없음을 확인
  • collection.shouldBeUnique() : 컬렉션의 모든 element가 중복이 없는지 확인
  • collection.shouldContain(element) : 컬렉션에 지정된 element가 포함되어 있는지 확인
  • collection.shouldContainAll(e1, e2,..., en) : 컬렉션에 순서가 중요하지 않은 나열된 모든 element가 포함되어 있는지 확인
  • collection.shouldContainDuplicates() : 컬렉션에 하나이상의 중복 element가 포함되어 있는지 확인
  • collection.shouldContainExactly(e1, e2, ..., en) : 컬렉션이 정확히 주어진 값을 포함하고 다른 것은 순서대로 포함하지 않음을 확인
  • collection.shouldContainExactlyInAnyOrder(e1, e2,..., en) : 컬렉션이 순서에 상관없이 정확히 주어진 값을 포함하고 다른 것은 포함하지 않음을 확인
  • collection.shouldContainNull() : 컬렉션에 하나 이상의 null element가 포함되어 있는지 확인
  • collection.shouldContainOnlyNulls() : 컬렉션이 null elements만 포함하거나 비어 있는지 확인
  • collection.shouldHaveSingleElement(element) : 컬렉션이 하나의 element만 포함하는지 확인
  • collection.shouldHaveSingleElement { block } : 컬렉션이 주어진 술어에 의해 하나의 element를 포함하는지 확인
  • collection.shouldHaveSize(length) : 컬렉션이 정확히 주어진 길이인지 확인
  • collection.shouldBeSingleton() : 컬렉션에 element가 하나만 포함되어 있는지 확인
  • collection.shouldBeSingleton { block } : 컬렉션이 단 하나의 element인지 확인한 후 이 element를 사용하여 block실행
  • collection.shouldHaveLowerBound(element) : 주어진 element가 컬렉션의 모든 element보다 작거나 같은지 확인. (Comparable을 구현하는 element에 대해서만 작동)
  • collection.shouldHaveUpperBound(element) : 주어진 element가 컬렉션의 모든 element보다 크거나 같은지 확인. (Comparable을 구현하는 요소에 대해서만 작동)
  • collection.shouldBeSmallerThan(col) : 컬렉션이 다른 컬렉션보다 작은지 확인
  • collection.shouldBeLargerThan(col) : 컬렉션이 다른 컬렉션보다 큰지 확인
  • collection.shouldBeSameSizeAs(col) : 컬렉션의 크기가 다른 컬렉션과 동일한지 확인
  • collection.shouldHaveAtLeastSize(n) : 컬렉션의 크기가 n 이상인지 확인
  • collection.shouldHaveAtMostSize(n) : 컬렉션의 크기가 최대 n인지 확인
  • list.shouldBeSorted() : 목록이 정렬되었는지 확인
  • list.shouldContainInOrder(other) : 이 목록에 주어진 목록이 순서대로 포함되어 있는지 확인
  • list.shouldExistInOrder({ element },...) : 이 목록에 술어와 순서대로 일치하는 element가 포함되어 있는지 확인. 다른 element는 술어와 일치하는 element 주변이나, element 사이에 나타날 수 있음
  • list.shouldHaveElementAt(index, element) : 이 목록이 주어진 index에 주어진 element를 포함하는지 확인
  • list.shouldStartWith(lst) : 이 목록이 주어진 목록의 element로 순서대로 시작하는지 확인
  • list.shouldEndWith(lst) : 이 목록이 주어진 목록의 element로 순서대로 끝나는 것을 확인
  • value.shouldBeOneOf(collection) :특정 인스턴스가 컬렉션에 포함되어 있는지 확인
  • collection.shouldContainAnyOf(collection) : 컬렉션에 있는 element 중 적어도 하나가 있음을 확인
  • value.shouldBeIn(collection) : object가 컬렉션에 포함되어 있는지 확인. (참조가 아닌 값으로 확인함)

Result

  • result.shouldBeSuccess() : Result가 Success인지 확인
  • result.shouldBeSuccess(value) : Result가 Success이고 value와 동일한지 확인
  • result.shouldBeSuccess(block) : Result가 Success이면 블록을 실행하여 확인
  • result.shouldBeFailure() : Result가 Failure인지 확인
  • result.shouldBeFailureOfType <Type : Throwable>() : Result의 Failure의 타입이 동일한지 확인
  • result.shouldBeFailure(block) : Result가 Failure이면 블록을 실행하여 확인

Coroutine Channel

  • channel.shouldReceiveWithin(duration) : 채널이 기간 내에 수신 수신하는지 확인
  • channel.shouldReceiveNoElementsWithin(duration) : 채널이 기간 내에 어떤 요소도 수신하지 않는지 확인
  • channel.shouldHaveSize(n) : 닫기 전에 채널이 정확히 n개의 요소를 수신하는지 확인
  • channel.shouldReceiveAtLeast(n) : 채널이 >= n개의 요소를 수신하는지 확인
  • channel.shouldReceiveAtMost(n) : 채널이 닫기 전에 <=n 요소를 수신하는지 확인
  • channel.shouldBeClosed() : 채널이 닫혀 있는지 확인
  • channel.shouldBeOpen() : 채널이 열려 있는지 확인
  • channel.shouldBeEmpty() :채널이 비어 있음을 확인

 

참고자료 https://beomseok95.tistory.com/368#fun-spec
 

Kotest 알아보기

Kotest Index Kotest Index KoTest란 테스트 스타일 Fun Spec String Spec Should Spec Describe Spec Behavior Spec Word Spec Free Spec Feature Spec Expect Spec Annotation Spec 조건부로 테스트 실행하기 Co..

beomseok95.tistory.com

 

Comments