Abstract

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 specific 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.

Full Text
Published version (Free)

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call