Is there a way to check that a collection contains at least n elements from a list of expected elements (e_1, e_2, ..., e_m) for m >= n? I'm thinking something similar to IterableSubject.containsAnyOf(e_1, e_2, ...), which could be considered a special case where n = 1.
How do I check that a Collection contains at least N matching elements in google-truth?
1.9k Views Asked by Lars Olson At
1
There is currently no built-in proposition in
google-truthto verify that aCollectioncontains at least N elements from a set of candidates. You can determine the built-in vocabulary of propositions for aCollectionby looking at the available methods inIterableSubject.Since there is no built-in proposition, you have two main options for performing your assertion within
google-truth:isAtLeastSubjectFactorytoassertAboutCreating your own proposition is more work, but makes your test more readable and gives a lot better messages upon test failure. The following example demonstrates both options: