views:

415

answers:

4

I'm often creating custom assertion methods for my JUnit tests. eg:

public void assertArrays(String[] actual, String[] expected)

I was wondering if there were any decent third party libraries that can provide a wider range of assertions than what comes by default in JUnit.

Am using JUnit 4.

A: 

I do not know of any such library. However, you might not really need this.

JUnit contains assertEquals for most value types of the JDK. For your own classes, you can simply override the equals() method, and use assertEquals(Object,Object).

This is what I usually do for my own classes. Works well, and a proper equals() method is useful anyway.

sleske
+1  A: 

Google names their Asserts classes MoreAsserts. Here's one for one particular project and you can search for more, as most projects have their own and they are frequently open source'd.

Edit: Android has a pretty great one too, not sure if that source is available though.

Kai
Yup, that's the kind of thing I was after. Thanks. If anyone else knows of any others available, please post.
+3  A: 

There is standard method for this purposes in JUnit4: assertArrayEquals

Andrey Vityuk
Thanks Andrey, I had forgotten about that one.
+2  A: 

The one that has been around for ever is JUnit Addons.

Yishai