Skip to content

What is a Unit Test?

Dave Nicolette edited this page Dec 16, 2020 · 12 revisions

Home -> User Guide -> General User Guide -> About Unit Testing

The term unit test has no standard definition. Different people have different ideas in mind when they use the term.

What is a unit?

Cobol-check is mainly concerned with supporting existing (legacy) mainframe applications. In the mainframe world, a unit of code is usually considered to be a load module - what other people call an executable. IBM's zUnit product, for unit-testing mainframe programs, considers a load module as the "unit" to be tested. Reference: IBM: z/OS Automated Unit Testing Framework (zUnit) Overview.

Mainframers use the term compilation unit to refer to the set of sources that are compiled together, and the term run unit to refer to the set of object-code artifacts that are executed together. They generally do not think in terms of testing finer-grained subsets of code in isolation, as we do with other languages on other platforms. The reason is the system was never designed to allow bits and pieces of procedural-language programs to run separately from the program of which they are a part.

When unit testing code in Java, C#, Python, Ruby, and other object-oriented languages, we consider a single method to be a unit, and a single logical path through that method to be a suitable unit test case. For functional languages and general languages that have functional programming features, like JavaScript or F#, a module or a single function might be considered a unit of code.

Unit test code can invoke a single method or function alone, without running the whole program, and with no need to set up the program's usual execution environment, and check the result of the call. Cobol does not offer a built-in way to do the equivalent: To invoke a single paragraph alone, and check the result of the perform.

What is a unit test?

Michael Feathers came up with a list of characteristics that indicate a test case is not a unit test A Set of Unit Testing Rules (Michael Feathers). He writes:

A test is not a unit test if:

  • It talks to the database
  • It communicates across the network
  • It touches the file system
  • It can't run at the same time as any of your other unit tests
  • You have to do special things to your environment (such as editing config files) to run it.
Clone this wiki locally