Unit testing ';这';在静态模拟Mockito中不可用
在调试模式下运行时,我将看到this.id='this'不可用。不确定在这里设置值。我尝试使用set设置值,但仍然存在相同的问题。我正在使用intellij 在课堂上Unit testing ';这';在静态模拟Mockito中不可用,unit-testing,testing,junit,mockito,integration-testing,Unit Testing,Testing,Junit,Mockito,Integration Testing,在调试模式下运行时,我将看到this.id='this'不可用。不确定在这里设置值。我尝试使用set设置值,但仍然存在相同的问题。我正在使用intellij 在课堂上 public class Customer { private int id; public void setId(int id) { this.id=id; } public int getId() { return this.id; }
public class Customer
{
private int id;
public void setId(int id)
{
this.id=id;
}
public int getId()
{
return this.id;
}
public void doThis(){
try
{
ResourceBundle resourcebundle=ResourceBundle.getBundle("account-local",Locale.ENGLISH);
if(this.id==1)
{
this.id=10;
}
else
{
this.id=15;
}
}
catch(Exception e)
{
}
}
}
静态方法具有mockito内联依赖项的测试类
public class CustomerTest
{
@Mock
private ResourceBundle accountManagementLocale;
@Test
public void doThis()
{
try (MockedStatic<ResourceBundle> utilities = Mockito.mockStatic(ResourceBundle.class)) {
utilities.when(() -> ResourceBundle.getBundle("account-local",Locale.ENGLISH))
.thenReturn(accountManagementLocale);
changeAccount.modifyAccount();
}
}
}
公共类客户测试
{
@嘲弄
私有资源包accountManagementLocale;
@试验
公开无效
{
try(MockedStatic实用程序=Mockito.mockStatic(ResourceBundle.class)){
utilities.when(()->ResourceBundle.getBundle(“account local”,Locale.ENGLISH))
.然后返回(accountManagementLocale);
changeAccount.modifyAccount();
}
}
}
当我在调试模式下运行时,我会看到this.id='this'不可用
我试图在网上调查,但没有找到任何解决办法