Reputation: 131
I am curious to understand how Java tests its APIs. Let's say,I am interested in the class ConcurrentHashMap, will there be any unit tests for this class? If so, is it available for public?
Upvotes: 8
Views: 2106
Reputation: 47176
When you say "Java" you probably mean the Java Development Kit (JDK), which comes as OracleJDK and OpenJDK (OracleJDK is essentially OpenJDK with a few extras). OpenJDK is open-source; and the source code for all of its projects can be found here:
In particular, here is a browsable version of the jdk7 project directory.
I am curious to understand how Java tests its APIs. Let's say,I am interested in the class ConcurrentHashMap, will there be any unit tests for this class? If so, is it available for public?
Yes, for a list of all jdk7 tests look in jdk7/jdk/test.
If you are interested in ConcurrentHashMap
tests, look in jdk7/jdk/test/java/util/concurrent/ConcurrentHashMap:
NOTE: The JDK tests may look a bit awkward because it does not use JUnit, it uses JTreg.
Upvotes: 9
Reputation: 1936
You probably won't be able to get the source (and thus the testing code) for Oracle's Java. However, since OpenJDK theoretically follows the same specifications for behavior as Oracle Java (at least for all the parts of it that I'm familiar with), you could perhaps use their unit tests to test your library. The source for OpenJDK's jdk8
can be browsed here (see the test
directory for tests), and you can find other versions of java at their main page.
However, as Erranda points out, you should really ask yourself if you want to test the existing libraries. They are probably more thoroughly tested than anything you'll end up writing already, and unless you want to recompile Java from source after finding an issue (which could lead to compatibility problems), what good would finding a bug in the libraries do?
Upvotes: 0
Reputation: 1467
Any class packaged inside jdk like ConcurrentHashMap is tested and you don't need to worry almost all the cases. If you implementing a well defined interfaces then there are test cases available which can run against your API and check whether it's complacency. In addition if you define a new API which you will expose, you have to write your test cases using JUnit or TestNg. Here the purpose of your test cases should be checking whether your API giving expected results. If you cover all the combination of using your API then you can identify when there is a regression.
Offtopic : Integration testing suppose to test the whole project when all the components are integrated.
[Update] If you really need to test ConcurrentHashMap you can use a sample project which uses ConcurrentHashMap, please keep in mind that you better choose multi-thread project.
Upvotes: 0