Created
September 21, 2016 12:36
-
-
Save parahall/c1a2df70470a45e386d502e611b477e8 to your computer and use it in GitHub Desktop.
Mockito_problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
androidTestCompile 'junit:junit:4.12' | |
androidTestCompile 'org.mockito:mockito-core:1.10.19' | |
androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4' | |
androidTestCompile 'com.crittercism.dexmaker:dexmaker-mockito:1.4' | |
androidTestCompile 'com.crittercism.dexmaker:dexmaker-dx:1.4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log; | |
public class ClassWithInnerObject { | |
private final InnerObject innerObject; | |
public ClassWithInnerObject() { | |
innerObject = new InnerObject(); | |
} | |
public void callInnerObjectMethod() { | |
innerObject.outerFunc(); | |
} | |
public void outerFunc() { | |
innerFunc(); | |
} | |
public void innerFunc() { | |
Log.d("XXX", "innerFunc: called"); | |
} | |
public class InnerObject { | |
public void outerFunc() { | |
innerFunc(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.test.runner.AndroidJUnit4; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.mockito.Mockito; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.times; | |
import static org.mockito.Mockito.verify; | |
/** | |
* Instrumentation test, which will execute on an Android device. | |
* | |
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |
*/ | |
@RunWith(AndroidJUnit4.class) public class SpyVerifyTest { | |
@Test public void myInnerTestWorking() { | |
ClassWithInnerObject p = new ClassWithInnerObject(); | |
ClassWithInnerObject spy = Mockito.spy(p); | |
spy.outerFunc(); | |
verify(spy, times(1)).innerFunc(); | |
} | |
@Test public void myInnerTestNotWorking() { | |
ClassWithInnerObject p = new ClassWithInnerObject(); | |
ClassWithInnerObject spy = Mockito.spy(p); | |
spy.callInnerObjectMethod(); | |
verify(spy, times(1)).innerFunc(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment