Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a testsuite for Java custom collections implementation?

Out of curiosity, I wrote an own simple implementation of Set for a special case (where the set of all possible entries is fixed, but it's no enum). It was actually quite easy, but obviously, my implementation is unusable without a lot of tests (and maybe even then, but that's another topic; it was mainly an exercise).

So is there any testsuite available I could use for unit-testing it?

like image 551
maaartinus Avatar asked Aug 15 '11 17:08

maaartinus


People also ask

Can we create custom collection in Java?

The Java platform allows you to write your own implementation of a core collection interface. It is easy to write your own implementation with the help of abstract implementations.

What implements a collection in Java?

Implementing Classes The Collection interface is implemented by AbstractCollection, AbstractList, AbstractQueue, AbstractSequentialList, AbstractSet, ArrayBlockingQueue, ArrayDeque, ArrayList, AttributeList, BeanContextServicesSupport, BeanContextSupport, ConcurrentHashMap.

What does .test do in Java?

Java testing provides thorough and functioning test cases that can test every aspect of your application. A JUnit test case is exactly what it sounds like: a test scenario measuring functionality across a set of actions or conditions to verify the expected result. JUnit is a simple framework to write repeatable tests.

What is the root interface of the collections API?

util. Collection is the root interface of Collections Framework. It is on the top of the Collections framework hierarchy.


1 Answers

Use the Guava SetTestSuiteBuilder.

https://github.com/google/guava/blob/master/guava-testlib/src/com/google/common/collect/testing/SetTestSuiteBuilder.java

Examples:

https://github.com/google/guava/blob/master/guava-testlib/src/com/google/common/collect/testing/TestsForSetsInJavaUtil.java

It is released as part of "guava-testlib" in maven central.

like image 78
Kevin Bourrillion Avatar answered Sep 25 '22 16:09

Kevin Bourrillion