Closed inhaledesign closed 4 years ago
@ClassRule
should be used in most cases as it would make your tests better in terms of performance. You could see the difference if you had multiple @Test
functions in your class.
E.g. it would work as following
@ClassRule
(executed once for the class)@Test
# 1@Test
# 2 @Test
# 3@Rule
(executed once for every test)@Test
# 1@Test
# 2@Test
# 3I used @Rule
in the sample because... ¯_(ツ)_/¯
I might change it at some point if you found it confusing.
@inhaledesign did you find my explanation informative enough?
Hey, sorry for not replying. Yeah, the explanation was very clear, thank you.
No worries, cheers.
In the README, there's directoins to use @ClassRule:
But in the code sample, the code uses an instance level @Rule https://github.com/blipinsk/disable-animations-rule/blob/f3bd9c934d4b139200ee97e1b2c108a2d122d7ff/sample/src/androidTest/java/com/bartoszlipinski/disableanimationsrule/sample/activity/MainActivityTest.java#L18-L25
This is maybe a minor point, but noticing the discrepancy I am left wondering if there is a reason to prefer one over the other?