Frage

Is there already some existing JUnit test for testing a BlockingQueue interface? Some class I can download, press play and then it turns red (hopefully green :-)), without me having to spend a day thinking of all test cases?

I googled but couldn't find anything.

some ideas?

EDIT: The test case that G_H provided was very good for debugging the basics. Is there maybe still a good test for heavy multithreaded use, that really provokes races and deadlocks?

War es hilfreich?

Lösung

Since the BlockingQueue interface is part of the Java concurrency utilities, which were developed under the Java Specification Request 166 (JSR-166), I figure the code from the corresponding technology compatibility toolkit (or "tck") should be a good starting point. After all, implementations of the spec must pass said kit's tests in order to be considered compatible.

I've had no luck getting it from the JCP site (maybe requires membership), but the resources seem to be available here. Of interest are BlockingQueueTest and its super class JSR166TestCase, the most recent revisions of which can be found respectively here and here. Seems to be licensed under creative commons, but I advise you to verify the reliability of the given link and licensing constraints vis-a-vis your use for yourself.

Fortunately all of this seems to be using JUnit. I'm not certain about the version, but they're using the testMethod convention rather than annotations. With some adaptation I guess this code could be good to get you going.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top