Book contents
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
8 - Unit Testing
Published online by Cambridge University Press: 05 July 2012
- Frontmatter
- Contents
- Foreword
- Preface
- 1 Introduction to Modern Fortran
- 2 Array-Valued Functions
- 3 Mathematical Abstractions
- 4 Memory Management
- 5 An Interface Problem
- 6 Interfacing to C: SQLite As an Example
- 7 Graphics, GUIs, and the Internet
- 8 Unit Testing
- 9 Code Reviews
- 10 Robust Implementation of Several Simple Algorithms
- 11 Object-Oriented Programming
- 12 Parallel Programming
- A Tools for Development and Maintenance
- B Caveats
- C Trademarks
- Bibliography
- Index
Summary
The subject of this chapter is a simple framework for automating one particular aspect of testing: unit tests. Unit tests focus on “small” parts of a program, typically single subroutines or functions. The idea is these tests give confidence in the correct operation of routines. As the code for these tests should be considered part of the program, you can repeatedly run them during development and maintenance of the whole system. Some development methods take this to the extreme. Test-driven development (TDD), for instance, prescribes that the tests be written first, before you start implementing the actual code.
This is just one way to develop a program, but thinking about the ways you can test a particular routine helps to define its functionality. Most importantly, however, such unit tests become part of the program. Therefore, testing at that level is not an afterthought, implemented in ad hoc one-off programs.
Testing Frameworks
Junit is a well-known framework for unit tests in a Java programming environment [37]. It has been seminal for a whole range of similar frameworks for all manner, of programming languages. Junit depends on explicit support from several language features that Fortran does not have, such as special annotations and the possibility to programmatically get a list of routine (method) names from a library. Nevertheless, it is quite possible to implement a unit testing framework in Fortran as well.
- Type
- Chapter
- Information
- Modern Fortran in Practice , pp. 114 - 120Publisher: Cambridge University PressPrint publication year: 2012