Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The @Rule > must be public ValidationError in Kotlin Junit test

I tried to use a unit test rule annotation and Android Studio didn't highlight any error here:

@Rule val htmlManager = HtmlManager()

However after executing the test following error happens:

org.junit.internal.runners.rules.ValidationError: The @Rule 'htmlManager' must be public.

How to fix this?

like image 757
donfuxx Avatar asked Nov 27 '17 10:11

donfuxx


1 Answers

The solution is to apply @Rule annotation to property getter:

@get:Rule
val htmlManager = HtmlManager()

more detail here: https://kotlinlang.org/docs/reference/annotations.html#java-annotations

see the fixed test case code here in my open-source project: https://github.com/appham/Sharemarks/commit/310c115d5a820be900abc321cc061aeab7af2e5a#diff-5e1e851ef5b9bb333abb96dec3199a94

like image 147
donfuxx Avatar answered Sep 27 '22 22:09

donfuxx