Hanbit the Developer

Why is @get:Rule used instead of @Rule in Kotlin? 본문

Mobile/Android

Why is @get:Rule used instead of @Rule in Kotlin?

hanbikan 2023. 2. 23. 20:46

Using test rules can help you write more efficient and effective tests, and can save you time by automating common testing tasks. And @Rule annotation is used to declare the test rule in JUnit. But in sunflower created by Google Android, @get:Rule is used instead of @Rule.

In Kotlin, properties are compiled to getter and setter in Java, rather than public fields. So we need to apply the @Rule annotation to the getter method. And the @get:Rule annotation in Kotlin apply the @Rule annotation to the getter method.