Ben
Ben

Reputation: 6887

JUnit assertion extensions

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.

Upvotes: 3

Views: 1987

Answers (4)

Yishai
Yishai

Reputation: 91881

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

Upvotes: 2

Andrey Vityuk
Andrey Vityuk

Reputation: 1019

There is standard method for this purposes in JUnit4: assertArrayEquals

Upvotes: 7

Kai
Kai

Reputation: 4027

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.

Upvotes: 1

sleske
sleske

Reputation: 83609

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.

Upvotes: 0

Related Questions