Hi all,
Today we landed
our first ADR (Architectural Decision Record). It's about introducing a new test dependency:
kotlin-test.
It's
not a big library, but it provides some quality of life improvements
for testing in Kotlin. It wraps the existing JUnit assertions you already know and use, and it adds a few new ones. Together they allow you to assert things in a
more Kotlin-idiomatic way, enable better code analysis in the compiler
and in Android Studio (e.g. smart casts after asserting something is not
null or of a specific type) and in some cases improve the default
messages when assertions fail.
I
encourage you to use kotlin-test assertions in new and existing tests.
They are fully interoperable with JUnit, so they can co-exist with JUnit
assertions even in the same function. We will run migrations to
update some existing assertions to kotlin-test where the improvements are greatest and add quick-fixes to Android Studio so you can learn about the new and improved APIs as you work on your tests.
kotlin-test
has been available in
libs.versions.toml and in Fenix tests for a couple of weeks. I also just landed a
stack that added it to most of
android-components. If you want to use it in a new component or an
existing one where it isn't available yet, feel free to add it in
build.gradle.
kotlin-test also provides @Test,
@BeforeTest, @AfterTest and @Ignore annotations, which are actually just
type aliases for JUnit annotations. They don't provide any real
benefits for us right now. But we might migrate all annotations to
kotlin-test later for consistency. Both work, but when in doubt stick to JUnit annotations for now.
If you have any questions, please let me know!
Best
Marcin