views:

47

answers:

2

Any Java unit testing framework that supports writing unit testing code like this:

Collection<AType> myCollection = objectUnderTest.doSomething();
assertCollectionContainsAtleast(myCollection, "a Expected value");

Meaning what I would like is some sort of iteration support with some sort of matcher attached.

+5  A: 

Take a look at Hamcrest, which contains assertions for many things, including collections. You can use hasItem, hasKey, hasValue etc.

Brian Agnew
Alright thanks! For anybody reading this, here is what it would like using HamcrestMatcher<AType> myMatcher= hasProperty("aPropertyInAType",is("aPropertyValue"));assertThat(myCollection,hasItem(myMatcher));
Konstantin
Mix Hamcrest with JDave(.org) and you will most likely never look back - welcome to the world of BDD.
Esko
A: 

You might also take a look at Unitil's assertion utilities.

cwash