我的理解是doReturn()
与mockito-kotlin一起使用是我必须在
val mockObj = mock<TheClass> {
on { method } doReturn something
}
如何指定必须使用CALLS_REAL_METHODS
?
或者我可以使用doReturn()
以val mockObj : TheClass = mock(Mockito.CALLS_REAL_METHODS)
代替其他方式使用doReturn()
吗?
只是为了澄清 - 这是一个when/whenever
(不是<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form id="form_submit">
<input type="text" id="username" name="username" required/>
<table>
<tr>
<th align="left">Full Name</th>
<td>
<input type="text" id="full_name" required/>
</td>
</tr>
<tr>
<th align="left">Password</th>
<td>
<input type="password" id="full_name" required/>
</td>
</tr>
<tr>
<th align="left">Confirm Password</th>
<td>
<input type="password" id="confirm_password" required/>
</td>
</tr>
<tr>
<th align="left">Department</th>
<td>
<input type="text" id="department" required/>
</td>
</tr>
<tr>
<th align="left">Supervisor</th>
</tr>
<tr>
<th align="left">E-mail Address</th>
<td>
<input type="email" id="email" required/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Create Account" id='btn_create'/>
</td>
</tr>
</table>
</form>
<script>
var button = document.getElementById("btn_create");
if (button)
button.addEventListener('click', createAccount, false);
function createAccount(evt){
var form_submit = document.getElementById("form_submit");
var isValid = form_submit.checkValidity();
alert('isValid: ' + isValid);
var username = form_submit.children.username.value;
evt.preventDefault();
return false;
}
</script>
</body>
</html>
)问题
答案 0 :(得分:2)
由于Mockito-Kotlin 1.2.0 mock()
采用可选参数:
val mockObj : TheClass = mock(defaultAnswer = Mockito.CALLS_REAL_METHODS)
您可以使用存根机制再次覆盖单个方法的默认行为:
val mockObj = mock<TheClass>(defaultAnswer = Mockito.CALLS_REAL_METHODS) {
on { method() } doReturn something
}