Guava library for Java has unit test cases automatically generated:

Guava has staggering numbers of unit tests: as of July 2012, the guava-tests package includes over 286,000 individual test cases. Most of these are automatically generated, not written by hand, but Guava's test coverage is extremely thorough, especially for com.google.common.collect.

How they were generated? What techniques and technologies were used to design and generate them?

My guess

My first guess is they follow parametrized tests approach. The package com.google.common.collect.testing has a lot of classes with "Generator" in their names -- making it look like a framework for tests generation. The package com.google.common.collect.testing.features lists the features/constrains that a "collection" implementation (e.g., for a list, a set) should satisfy. So a test case parametrize what features a particular implementation should have.


My original question on Programmers SE got much attention from the community but no reasonable answer, so I'm trying to get it here. My motivation behind such a question is to learn more in general about techniques (parametrized tests, random tests, etc.) and technologies (code templates, etc.) used to automate test case generation.

2 Answers 2


(Also answered at the original question on programmers.stackexchange.com)

A large part of this mass of tests is for their collection implementations. They've written generic tests that exhaustively test the collection interfaces, and this generates a suite per implementation. See, for example, classes called CollectionAddAllTester, ListIndexOfTester.

This is all backed by a library called testlib, which ships as part of Guava. This is quite generic. It supports writing generic tests for any interface (not just collections). You can specify Features of possible implementations and test those (e.g. if your set is unmodifiable you expect a different outcome from set.add()), and when you run the tests you specify which features your implementation supports.

I wrote a post on how to write testlib generating suites for your own interfaces.


One possibility is the use of CodePro Analytix by Google which has a JUnit Test Case Generation feature.

  • Can you explain more how it works?
    – dzieciou
    Jun 13, 2013 at 7:46
  • Its probably similar to how SoapUI can read a webservice WSDL and then it knows how to generate all the stubs for all the endpoint methods. I would guess CodePro Analytix must use Reflection to generate tests (or at least the stubs)? This is a total guess: stab in the dark.
    – djangofan
    Aug 15, 2013 at 22:45
  • So it just generate stubs, correct?
    – dzieciou
    Aug 26, 2013 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.