International Journal of Computer Applications |
Foundation of Computer Science (FCS), NY, USA |
Volume 67 - Number 10 |
Year of Publication: 2013 |
Authors: Suma Shivaprasad, Nanditha Prasad |
10.5120/11435-6798 |
Suma Shivaprasad, Nanditha Prasad . Unit Testing Concurrent Java Programs. International Journal of Computer Applications. 67, 10 ( April 2013), 41-46. DOI=10.5120/11435-6798
Conventional unit-testing practices focus on testing small units of programs sequentially and are very likely to miss concurrent bugs such as race conditions, deadlocks and memory inconsistencies even when done extensively. They are not suitable for unit testing multithreaded programs. This paper outlines guidelines for writing effective unit tests for concurrent Java programs. It also explores and compares the frameworks available currently for writing such tests. The most widely used unit testing frameworks for Java - TestNG and JUnit - do not provide good support for testing concurrent issues. Other frameworks such as MultiThreadedTC and Concurrency Analyzer allow the coordination of unit test's threads to produce a speci?c scheduling. However, it is the responsibility of the developer to test for all possible interleavings and scheduling of threads to unearth existing bugs and hence they are a deterministic way of approaching the problem. This paper presents an alternate approach to the problem by integrating TestNG with the Java Path Finder(JPF) software model checker. JPF can be used to identify all possible interleavings of threads across execution paths to non deterministically detect concurrent bugs. In addition to this, it detects deadlocks by checking if all the threads have reached a blocked state at any point of execution. Adoption of such practices have helped in reducing concurrency related issues in our platforms to a great extent. It has helped in identifying issues early on in the development cycle and better reliability. Many open source platforms such as Ehcache run concurrent unit tests as part of their development process to maintain code quality. This, augmented with stress testing concurrency tools greatly help in improving the quality of code.