有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用不同参数的junit Mockito java测试方法调用

我试图测试这个方法,看看是否在没有参数的情况下调用searchProfile:

public void searchProfile(Long searchTerm) {
    this.searchTerm = searchTerm;
    searchProfile();
}

public void searchProfile() {
     //...
}

这是我的测试用例,我用一个参数调用方法,并期望调用没有参数的方法

@Test
public void testSearchProfile() throws Exception {
    CustomerProfileController sutStub = Mockito.mock(CustomerProfileController.class);

    doNothing().when(sutStub).searchProfile();

    sutStub.searchProfile(0L);

    verify(sutStub, times(1)).searchProfile();
}

我怎样才能做到这一点?现在它只给了我一个错误:

Comparison Failure:

Expected: customerProfileController.searchProfile();

Actual: customerProfileController.searchProfile(0);


共 (0) 个答案