June 2018
Beginner
722 pages
18h 47m
English
The branching assert statement can be used for validation of the data in application testing, especially for accessing rarely used execution paths or combinations of data. The unique aspect of this capability is that the code is not executed unless the JVM is run with the option -ea.
A full discussion of the assert statement's functionality and possible application is outside the scope of this book. We will just demonstrate its basic usage and how to turn it on using IntelliJ IDEA.
Look at the following code:
public class AssertDemo { public static void main(String... args) { int x = 2; assert x > 1 : "x <= 1"; assert x == 1 : "x != 1"; }}
The first assert statement evaluates the expression x > 1 and stops program ...
Read now
Unlock full access