How Java Programmer Test Exceptional Behavior
Accepted for publication at the 2021 Mining Software Repositories Conference (MSR 2021)
Exceptions often signal faulty or undesired behavior; hence, high-quality test suites should also target exceptional behavior. This paper is a large-scale study of exceptional tests—which exercise exceptional behavior—in 1 157 open-source Java projects hosted on GitHub.
We analyzed JUnit exceptional tests to understand what kinds of exceptions are more frequently tested, what coding patterns are used, and how features of a project, such as its size and number of contributors, correlate to the characteristics of its exceptional tests.
We found that:
- exceptional tests are only 13% of all tests, but tend to be larger than other tests on average;
- unchecked exceptions are tested twice as frequently as checked ones;
- 42% of all exceptional tests use try/catch blocks and usually are larger than those using other idioms;
- and bigger projects with more contributors tend to have more exceptional tests written using different styles.
The paper also zeroes in on several detailed examples involving some of the largest analyzed projects, which refine the empirical results with qualitative evidence. The study’s findings, and the capabilities ofthe tool we developed to analyze exceptional tests, suggest several implications for the practice of software development and for follow-up empirical studies.