New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mocking System.currentTimeMillis #1590
Comments
Wrap System.currentTimeMillis to TimeProvider (or any other name) class. Then Mock the provider. much easier |
Hi it would help for source that is under my control, but wont help in case that the call is originated from jars i`m using. |
This is true for 3.0, but not 2.4. |
ShadowSystemClock should work correctly in 3.0-SNAPSHOT, so I'm going to close this. If you still have issues after upgrading to 3.0, please re-open. |
Still having an issue mocking currentTimeMillis with 3.0. The ShadowSystemClock methods are getting called from other shadows but not from my own code under test. For example: @Test
public void testCurrentTime() {
// Calls use ShadowSystemClock
new Notification();
// Does not call out to ShadowSystemClock
mSomeClassUnderTest.doSomethingWithCurrentTime();
} The first case uses ShadowWrangler as expected. However, in the second case, ShadowWrangler never gets invoked at all. Any ideas about why this might be happening? |
Hi, I`m using robolectric 2.4 with mockito.
During testing of my App, I need to set time in order to test time specific functionality.
From what i had observed from the sources of robolectric, especially ShadowWrangler class, calls to
System.currentTimeMillis sould be intercepted, and provided via ShadowSystemClock, but it did not work for me.
I had also tried with robolecric and powermockito, but could not make it working, even with
powermock-classloading-xstream.
Thanks.
The text was updated successfully, but these errors were encountered: