Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Last active September 7, 2016 07:05
Show Gist options
  • Save Tanapruk/7ea36cdbb6b483bf2647aac4569fa2f1 to your computer and use it in GitHub Desktop.
Save Tanapruk/7ea36cdbb6b483bf2647aac4569fa2f1 to your computer and use it in GitHub Desktop.
Test Framework verifyStatic
  1. dependencies
testCompile 'org.powermock:powermock-api-mockito:1.6.5'
testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.5'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.5'
  1. ใส่ tag บน class
@RunWith(PowerMockRunner.class)
@PrepareForTest(Mobile.class)
  1. กำหนด mock แค่ใส่ข้างล่าง ก็จะ mockStatic ทั้ง class เลย โดยเทียบเท่า doNothing
PowerMockito.mockStatic(Mobile.class);
  1. จะ verify ต้องใส่ method ที่จะ verify ในบรรทัดถัดไป
verifyStatic();
Mobile.setMobileNumber("0123456789");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment