Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以称之为JUnit测试中的存根吗?_Junit_Mockito - Fatal编程技术网

我可以称之为JUnit测试中的存根吗?

我可以称之为JUnit测试中的存根吗?,junit,mockito,Junit,Mockito,代码- 在上面的代码中,我可以调用下面的行作为存根或测试存根吗 @Test public void testAddition() { Mockito.when(adder.add(Mockito.anyInt(),Mockito.anyInt())).thenReturn(22); //is this stub Integer result = calculator.add(Integer.valueOf(10), Integer.valueOf(12)); assertEqual

代码-

在上面的代码中,我可以调用下面的行作为存根或测试存根吗

@Test
public void testAddition() {
  Mockito.when(adder.add(Mockito.anyInt(),Mockito.anyInt())).thenReturn(22);  //is this stub
  Integer result = calculator.add(Integer.valueOf(10), Integer.valueOf(12));
  assertEquals(Integer.valueOf(22),result);
}
如果没有,这条线的技术术语是什么,肯定会有一些


提前感谢。

是的,您可以将该行称为存根或测试存根

正如我们所知,存根是一个带有预编程返回值的假类。 存根基本上被注入到被测试的类中,以提供对作为输入测试的内容的绝对控制。
这一行实际上就是这样。

酷。。欢迎和感谢+1
这一行实际上就是这样的
  Mockito.when(adder.add(Mockito.anyInt(),Mockito.anyInt())).thenReturn(22);  //is this stub