How to use Iterable.shouldContainAll method of io.kotest.matchers.collections.containAll class

Best Kotest code snippet using io.kotest.matchers.collections.containAll.Iterable.shouldContainAll


Source:containAll.kt Github


Full Screen

1package io.kotest.matchers.collections2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldNot6fun <T> Iterable<T>.shouldContainAll(vararg ts: T) = toList().shouldContainAll(ts)7fun <T> Array<T>.shouldContainAll(vararg ts: T) = asList().shouldContainAll(ts)8fun <T> Collection<T>.shouldContainAll(vararg ts: T) = this should containAll(*ts)9infix fun <T> Iterable<T>.shouldContainAll(ts: Collection<T>) = toList().shouldContainAll(ts)10infix fun <T> Array<T>.shouldContainAll(ts: Collection<T>) = asList().shouldContainAll(ts)11infix fun <T> Collection<T>.shouldContainAll(ts: Collection<T>) = this should containAll(ts)12fun <T> Iterable<T>.shouldNotContainAll(vararg ts: T) = toList().shouldNotContainAll(ts)13fun <T> Array<T>.shouldNotContainAll(vararg ts: T) = asList().shouldNotContainAll(ts)14fun <T> Collection<T>.shouldNotContainAll(vararg ts: T) = this shouldNot containAll(*ts)15infix fun <T> Iterable<T>.shouldNotContainAll(ts: Collection<T>) = toList().shouldNotContainAll(ts)16infix fun <T> Array<T>.shouldNotContainAll(ts: Collection<T>) = asList().shouldNotContainAll(ts)17infix fun <T> Collection<T>.shouldNotContainAll(ts: Collection<T>) = this shouldNot containAll(ts)18fun <T> containAll(vararg ts: T) = containAll(ts.asList())19fun <T> containAll(ts: Collection<T>): Matcher<Collection<T>> = object : Matcher<Collection<T>> {20 override fun test(value: Collection<T>): MatcherResult {21 val missing = ts.filterNot { value.contains(it) }22 val passed = missing.isEmpty()23 val failure =24 { "Collection should contain all of ${ts.printed().value} but was missing ${missing.printed().value}" }25 val negFailure = { "Collection should not contain all of ${ts.printed().value}" }26 return MatcherResult(passed, failure, negFailure)27 }28}...

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:


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?