blipinsk / disable-animations-rule

JUnit TestRule for Android instrumented tests, which automatically disables and enables animations
Apache License 2.0
32 stars 3 forks source link

README instructions do not match sample #2

Closed inhaledesign closed 4 years ago

inhaledesign commented 4 years ago

In the README, there's directoins to use @ClassRule:

@ClassRule
public static DisableAnimationsRule animationsRule = new DisableAnimationsRule();

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?

blipinsk commented 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

Using @ClassRule (executed once for the class)

  1. Disabling animations
  2. executing @Test # 1
  3. executing @Test # 2
  4. executing @Test # 3
  5. Enabling animations

Using @Rule (executed once for every test)

  1. Disabling animations
  2. executing @Test # 1
  3. Enabling animations
  4. Disabling animations
  5. executing @Test # 2
  6. Enabling animations
  7. Disabling animations
  8. Executing @Test # 3
  9. Enabling animations

I used @Rule in the sample because... ¯_(ツ)_/¯ I might change it at some point if you found it confusing.

blipinsk commented 4 years ago

@inhaledesign did you find my explanation informative enough?

inhaledesign commented 4 years ago

Hey, sorry for not replying. Yeah, the explanation was very clear, thank you.

blipinsk commented 4 years ago

No worries, cheers.