google-developer-training / android-fundamentals-apps-v2

Other
649 stars 2.63k forks source link

Android Java Fundamentals codelab: 03.2: Unit tests #365

Closed kkors closed 1 year ago

kkors commented 1 year ago

Describe the problem The assignment reads:

Challenge 1: Dividing by zero is always worth testing for, because it is a special case in arithmetic. How might you change the app to more gracefully handle divide by zero? To accomplish this challenge, start with a test that shows what the right behavior should be.

Remove the divTwoNumbersZero() method from CalculatorTest, and add a new unit test called divByZeroThrows() that tests the div() method with a second argument of zero, with the expected result as IllegalArgumentException.class. This test will pass, and as a result it will demonstrate that any division by zero will result in this exception.

This input does not trigger an IllegalArgumentException since dividing by 0 in floating point operations equals positive Infinity. The previous step even demonstrates it in the solution code of the unit tests and the proposed solution executes without errors.

In which lesson and step of the codelab can this issue be found? Android Java Fundamentals codelab: 03.2: Unit tests Step 5 Coding Challenges

codelab: android-fundamentals

jlulovics commented 1 year ago

Hello! Thank you for your feedback. This codelab is out of date and no longer maintained. Instead, please refer to the Android Basics with Compose course for the latest recommended practices. If you are looking for content on Views, you can check out the Android Basics in Kotlin course.