public void orderBookTest() { Book expectBook = new Book(1L, "钢铁是怎样炼成的", "书架A01"); Mockito.when(bookService.orderBook(any(String.class))).thenReturn(expectBook); Book book = studentService.orderBook(""); System.out.println(book); Assert.assertTrue("预定书籍不符", expectBook....
private ExpectedException exception = ExpectedException.none(); @Test public void testGetStu() { // 模拟依赖方法 Long code = 123L; Mockito.doReturn(null).when(StuTunnel).get(code); // 调用被测方法 exception.expect(ExampleException.class); exception.expectMessage("异常信息", code)); StStuvi...
1)@Test: 定义一个测试方法 @Test (excepted=xx.class): xx.class 表示异常类,表示测试的方法抛出此异常时,认为是正常的测试通过的 @Test (timeout = 毫秒数) : 测试方法执行时间是否符合预期。 2) @BeforeClass: 在所有的方法执行前被执行,static 方法全局只会执行一次,而且第一个运行。 3) @AfterClass:...
Mockito中有Stub,所谓存根或者叫打桩的概念,上面案例中的Mockito.when(bookService.orderBook(any(String.class))).thenReturn(expectBook);就是打桩的含义,先定义好如果按照既定的方式调用了什么,结果就输出什么。然后在使用Book book = studentService.orderBook(""); 即按照指定存根输出指定结果。 @Test public voi...
JUnit 官网:https://junit.org/。JUnit 是一个用于编写可重复测试的简单框架。它是用于单元测试框架的 xUnit 体系结构的一个实例。 JUnit 的特点: (1) 针对于 Java 语言特定设计的单元测试框架,使用非常广泛。 (2) 特定领域的标准测试框架。 (3) 能够在多种 IDE 开发平台使用,包含 Idea、Eclipse 中进行集成...
1、@Test(expected=xxx)方式:当抛出的异常与expected参数指定的异常相同时,测试通过。 2、try...fail...catch...方式:捕捉具体待测语句的异常信息并断言,当没有异常被抛出的时候fail方法会被调用,输出测试失败的信息。 3、ExpectedException Rule方式:使用Rule标记来指定一个ExpectedException,并在测试相应操作之前指...
public class CircleTest { @Test public void testGetArea() { double expectArea = 3.14D; Circle circle = PowerMockito.mock(Circle.class); PowerMockito.when(circle.getArea()).thenReturn(expectArea); double actualArea = circle.getArea(); Assert.assertEquals("返回值不相等", expectArea, actualArea...
Let’s start with a test of the helper method checkConsultantAvailability verification of the consultant’s availability. We expect an IllegalStateException if no Consultant implementation was found. The static method Mockito#when records expected behavior for an instance returned by the Mockito#mock ...
@TestpublicvoidtestScanner()throws Exception{Scanner scanner=newScanner(System.in);String line=scanner.nextLine();System.out.println(line);} 发现带@Test注解的方法里无法使用Scanner去读取控制台的文本。 常见的解决方案是写一个main方法中。 但是单测不应该依赖控制台的输入,应该转换成其他方式。
调用execute() 添加任务;小于corePoolSize 立马执行,大于等于放入队列;当队列装满且小于maximumPoolSize,立刻执行;当队列装满且大于等于maximumPoolSize,线程池抛出 RejectExecutionException 线程完成当前任务,从队列中拿取下一个任务执行 当线程不执行任务且超过keepAliveTime,当线程数大于corePoolSize,线程会被停掉,当所有...