November 2024
Intermediate to advanced
300 pages
7h 12m
English
Most of the assertions in your tests will be straight-up comparisons of expected outcomes to actual outcomes: is the average credit history 780? Sometimes, however, direct comparisons aren’t the most effective way to describe the expected outcome.
For example, suppose you’ve coded the method fastHalf that uses bit shifting to perform integer division by two. The code is trivial, as are some core tests:
| | public class MathUtils { |
| | static long fastHalf(long number) { |
| | return number >> 1; |
| | } |
| | } |
| | import org.junit.jupiter.api.Test; |
| | import static org.junit.jupiter.api.Assertions.assertEquals; |
| |
Read now
Unlock full access