power mock 使用 静态方法 博客分类: powermock powermock
程序员文章站
2024-02-15 09:57:34
...
引用
<properties>
<powermock.version>1.4.10</powermock.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@RunWith(PowerMockRunner.class) @PrepareForTest(ContextManager.class) public class TestTableDdlSeq { @Test public void testHandlePriorityTables() throws Exception{ PowerMockito.mockStatic(ContextManager.class); //TalePriorityDaoImpl impl = spy(new TalePriorityDaoImpl()); //mock(TalePriorityDaoImpl.class); //TalePriorityDaoImpl impl = mock(TalePriorityDaoImpl.class); TablePriorityDaoImpl impl = spy(new TablePriorityDaoImpl()); PowerMockito.when(ContextManager.getReference("tablePriorityDao", TablePriorityDaoImpl.class)).thenReturn(impl); PowerMockito.when(impl.getFullName()).thenReturn("123"); System.out.println(impl.getFullName()); }
上一篇: spring-boot 起步