使用无效方法的Mockito

时间:2018-06-26 08:30:24

标签: mockito

我想测试返回void的方法。 我应该纠正什么?

# What host address to start the server on. By default, Livy will bind to all network interfaces.
livy.server.host = 0.0.0.0

# What port to start the server on.
livy.server.port = 8998

# What spark master Livy sessions should use.
livy.spark.master = local

# What spark deploy mode Livy sessions should use.
livy.spark.deploy-mode = client

# List of local directories from where files are allowed to be added to user sessions. By
# default it's empty, meaning users can only reference remote URIs when starting their
# sessions.
livy.file.local-dir-whitelist= /home/user/.livy-sessions/

1 个答案:

答案 0 :(得分:0)

您应该在测试方法中直接或间接通过clientService与模拟进行交互。您的评论中有一个例外,因为测试期间没有调用saveClient

之后,您可以验证是否使用特定参数调用方法。它看起来应该类似于以下内容:

@Test
public void saveClient() {
   // Any interaction with the mock, like:
   clientDaoMock.saveClient(aClient)
   verify(clientDaoMock, times(1)).saveClient(any(Client.class));
}