1

I have an ImageView that is rotated using RotateAnimation(). I am writing a test case where I want to test that after a button is clicked this view is rotated. So I thought that I can get the rotation angle before the click and after it to check the difference:

oldRotationDegrees = view.getRotation();
//click that button and wait for 3 seconds
assertTrue(Math.abs(view.getRotation() - oldRotationDegrees) > 0);

However this difference is always 0, because getRotation() always returns 0. I have checked that there is really a rotation visible, so it seems that RotateAnimation() doesn't affect the value returned by getRotation().

So how can I verify that the image has been rotated after the button is pressed?

In case it matters, I am using Robotium for these tests.

Update: I am now testing also with robolectric (unit tests) and the behaviour is (without surprise) the same.

Update 2: This answer https://stackoverflow.com/a/4213493/2160877 explains why this happens.

Community
  • 1
  • 1
dragi
  • 3,385
  • 5
  • 22
  • 40
  • post animation code. possible `setFillAfter(true)` could be used to resolve this. – r2DoesInc Sep 03 '14 at 16:08
  • @r2DoesInc When the button is clicked there are a sequence of RotateAnimation() started(with different end degrees) and it is rotating until the button is clicked again. So I don't think setFillAfter(true) will help to resolve the issue that I have which is just to verify (in a test environment) that the rotation has started. – dragi Sep 03 '14 at 16:15
  • fill after sets the animation properties to the view from how i understand it. without it, the animation only applies to how the view is visibly shown. give it a shot. – r2DoesInc Sep 03 '14 at 16:16
  • I have just checked the code and it already contains `mAnimation.setFillEnabled(true); mAnimation.setFillAfter(true);` – dragi Sep 03 '14 at 16:18
  • Check if the width of the view also returns 0, please – Víctor Albertos Sep 03 '14 at 16:37
  • @valbertos The width value returned is not 0 – dragi Sep 04 '14 at 06:22
  • @helleye did you find a solution to this problem? I am seeing the exact same behavior, getRotation() keeps returning null even after the image is successfully rotated by 180 degrees. – Anton Cherkashyn May 13 '15 at 03:41
  • @AntonCherkashyn Not yet... So I skip testing this, unfortunately. – dragi May 13 '15 at 07:03

0 Answers0