Skip to content

Demonstrates how to perform a date calculation to determine the age of a person in years using Kotlin extension functions.

Notifications You must be signed in to change notification settings

hgbrown/kotlin-extensions-age-calculator-demo

Repository files navigation

Age calculation using Kotlin extension function with JUnit 5 Tests

Video: Using Kotlin extension functions to calculate age with tests in JUnit 5

Demonstrates how to perform a date calculation to determine the age of a person in years using Kotlin extension functions. Kotlin's extension functions make it extremely convenient to attach the functionality to an existing LocalDate class that leads to very readable code.

This demo shows how to expose the age calculation as an extension function to the LocalDate class as well as how to test code that relies on the current date without creating brittle tests that pass one day anf dail the next without any code changes having taken place.

This demo depends on:

  • Gradle (v 6.8.3)
  • Kotlin (v 1.4.31)
  • JUnit (v 5.7.1)
  • JUnit Params (v 5.7.1)
  • Strikt (v 0.29.0)

Building the code

To build the code, run:

./gradlew build

Running the tests

To run the tests:

./gradlew test

About

Demonstrates how to perform a date calculation to determine the age of a person in years using Kotlin extension functions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages