这是我尝试过的:
#!/bin/bash
#SBATCH --nodes 3
#SBATCH --ntasks-per-node 5
# fisrt run a.out in background
srun ./a.out &
# then run b.out
srun ./b.out
# after b finished, kill a
# I dont know how to do that...
我也嘲笑了中间步骤,即@Test
public void local_host_test() {
InetAddress inetAddress = Mockito.mock(InetAddress.class);
Mockito.when(inetAddress.getHostAddress()).thenReturn("127.0.0.1");
InetSocketAddress inetSocketAddress = Mockito.mock(InetSocketAddress.class);
Mockito.when(inetSocketAddress.getAddress()).thenReturn(inetAddress);
Mockito.when(inetSocketAddress.getPort()).thenReturn(22);
Assert.assertThat(inetSocketAddress.getAddress().getHostAddress(), Is.is("127.0.0.1"));
}
,但它抱怨如下:
InetAddress
我怎么了?
答案 0 :(得分:0)
查看Java文档
/**
* Gets the port number.
*
* @return the port number.
*/
public final int getPort() {
return holder.getPort();
}
/**
*
* Gets the {@code InetAddress}.
*
* @return the InetAdress or {@code null} if it is unresolved.
*/
public final InetAddress getAddress() {
return holder.getAddress();
}
和Mockito约束
在Mockito中不支持模拟最终方法。 Mockito和PowerMock之间的比较将详细解释问题。无法模拟最终方法-执行它们的实际行为没有任何异常
因此,它正在调用实际方法,而您正在配置NPE
。
使用 PowerMockito