Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.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
Java Junit验证命令执行_Java_Junit - Fatal编程技术网

Java Junit验证命令执行

Java Junit验证命令执行,java,junit,Java,Junit,我有一个测试用例: @Test(expected = IllegalArgumentException.class) public void testRunWithLessThanTwoParameters_IllegalArgumentException() throws Exception { final String[] args = { "Less Number of parameters" }; command = spy(new GenerateSumma

我有一个测试用例:

@Test(expected = IllegalArgumentException.class)
public void testRunWithLessThanTwoParameters_IllegalArgumentException() 
    throws Exception {

    final String[] args = { "Less Number of parameters" };
    command = spy(new GenerateSummaryReportCommand());      
    commandLine = new PosixParser().parse(new Options(),Arrays.copyOfRange(args, 0, args.length));
    assertEquals(0, command.run(commandLine));      
    verify(command, times(1)).usage();
}

我想知道assertEqual语句之后是否会执行verify

我假设
parse
正在抛出
IllegalArgumentException
。如果是这种情况,则不会执行
assertEquals
verify
,因为异常是在它们上面抛出的。抛出异常后进行验证的方法是将验证放在
catch
块中

@Test(expected = IllegalArgumentException.class)
public void testRunWithLessThanTwoParameters_IllegalArgumentException() 
   throws Exception {

     final String[] args = { "Less Number of parameters" };
     command = spy(new GenerateSummaryReportCommand());      

   try{
     commandLine = new PosixParser().parse(new Options(),Arrays.copyOfRange(args, 0, args.length));
   }catch (Exception e){
     assertEquals(0, command.run(commandLine));      
     verify(command, times(1)).usage();

      throw e;
   }
 }

请注意,我重新显示了异常,以允许进行
预期的
检查。

快速回答,如果assertEquals失败,则否。