This program-along exercise helps you get started with automated unit testing using JUnit Jupiter (JUnit 5).
First, you build a class TreasureChest. Then you'll test the class.
You will implement JUnit tests to test instance methods, static methods, and the constructor.
You will use assertions to compare the expected value with the actual value.
You will use annotations, fixtures, and lambda expressions to test for specific exceptions.
You will identify appropriate test data
You will use JUnit tests to identify bugs and to aid the problem-solving process to fix them.
Every so often, you will be asked to pause the video and to implement a specific task. Those interactive parts are designed to help you advance your programming skills and to improve your fluency. Give it a good try. Once you continue the video you'll find a solution to compare your code with.
Correction: 1:09:50
difference.compareTo(DELTA) returns a positive value when difference is greater than DELTA. Because of that, we should check whether the result is greater 0, not greater 1.
In case you wondered . . .
Why did the BigDecimal constant include a value different from 0.9675?
We created a new BigDecimal object by passing the floating-point number 0.9675.
Since 0.9675 can’t be represented precisely in type double, the BidDecimal object was created based on a slightly different value.
Can BigDecimal represent the exact value 0.9675?
Yes, it can. You can create a BigDecimal with the exact value by passing a string instead of the double. The constructor translates the string representation of the number into a BigDecimal.
E.g., private static final BigDecimal GOLD_PER_COIN = new BigDecimal("0.9675");
Why didn’t we use a string to create the BigDecimal?
Creating a BigDecimal object by passing an argument of type double to the constructor, demonstrated that the imprecision is passed on to the BigDecimal object. It also allowed us to demonstrate and practice the use of delta when we want to write JUnit tests that ignore small numerical differences.
Most of the time, we want to create a BigDecimal with the exact value. Remember, that we can do that by passing a string to the constructor.
Watch video Program Along JUnit5 online without registration, duration hours minute second in high quality. This video was added by user MargretPosch 22 July 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,031 once and liked it 30 people.