Reputation: 329
I have to create some JUnit test cases for Guava's ArrayListMultimap class, but so far, I'm clueless as to how I should proceed. I have successfully been able to create a normal testing class, ArrayListMultimapTest (which I've used to test the methods of the class), in which I added Guava's 15 release JAR file as an external library in the build path. But I've been specifically asked to create JUnit test cases for ArrayListMultimap, and I'm not sure as to how I should proceed. Any help would be appreciated, thanks!
Upvotes: 1
Views: 668
Reputation: 38444
Although the library is extensively tested by Google, you can do this easily yourself, if you want.
Now you're basically done and you can write your testcases - simply annotate any public void someName()
method with the @Test
annotation. If you won't have a public static main(String... args)
method in your code, then when you'll try to run the class, Eclipse will automatically run it with JUnit.
@Test
public void multimapAcceptsMultipleEqualValuesForOneKey() {
ListMultimap<String, String> listMultimap = ArrayListMultimap.create();
listMultimap.put("aha", "eh");
listMultimap.put("aha", "eh");
Assert.assertEquals(2, listMultimap.get("aha").size());
}
After that, try to dig into JUnit to learn all the goodness it offers you.
Upvotes: 2
Reputation: 46482
There's already such a test. No idea about maven, but just do
git clone https://code.google.com/p/guava-libraries
Then do everything you need to get in Eclipse running (which needs tons of JARs, but you get them all using maven, add them to the build path), open the file and click "run as junit test". Done.
__
Unless you suspect a specific problem, there's no need to write your own tests for Guava as it gets tested and used heavily. Anyway, even if feel like writing it, you should look at the existing ones first (they're sometimes a bit hard to understand as there's a whole testing framework, which is necessary to test that many classes thoroughly).
git is a version control system free to download here. It uses command line, but the only one you need to know is written above. maven is an incomprehensible "software project management and comprehension tool" also free to download and use.
As a programmer, you'll need them (or other such tools). Even more, you'll need to utfg a lot.
Upvotes: 2