[英]Mock variable in unit test android
在Google上搜索了有關如何在單元測試中模擬變量的信息,並看到了一些建議,對於我來說,它不起作用。 我的情況是
class Keys {
private static Keys sKeys;
private String enKey = null;
static synchronized sKeys getInstance() {
if(sKeys == null) {
sKeys = new Keys();
}
return sKeys;
}
Boolean isLocked() {
if(enKey == null ) {
return true;
}
return false;
}
}
這是我寫的課。 該課程的單元測試如下,
@RunWith(MockitoJUnitRunner.class)
public class KeysTest {
@Test
public void isLocked_Test() {
Keys key = Keys.getInstance();
Key.isLocked();
// Here in isLocked function I want to mock the enKey value to other than null
}
}
在這里,我想調用isLocked函數,並且我想將enKey變量值設置或模擬為非 null。
我該怎么做? 有人可以幫我嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.