Testing functional programs
Testing is a complex yet important aspect of software development. Java 8 has impacted how testing can be conducted. The intent of this section is not to explore all of the possible ways of testing Java 8 code, but to provide some insight into possible testing approaches.
JUnit is the standard for testing Java applications and is used to test the functional aspects of Java. Typically, a JUnit test is created to test a method by passing it data and comparing the return value to determine if the method executed properly. In this section, we will examine various testing approaches.
Testing lambda expressions
A significant consideration is whether to test a lambda expression at all. If it is too simple to break, then there is no need to test it. The question is, what is too simple? The answer to this depends on the situation. A simple lambda expression, such as, n -> 2*n
, is easy to understand and probably not worth the effort to test it. However, a more complicated...