静态包
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.powermock.api.mockito.PowerMockito.*;
类
@RunWith(PowerMockRunner.class)
@PrepareForTest({YouStaticClass.class})
mock以及初始化
/**
* 使用 @InjectMocks, 测试对象
*/
@InjectMocks
private TestService ts;
/**
* 使用@mock,测试对象依赖的对象
*/
@Mock
private DependencyService ds;
@Before
public void before(){
// 使模拟生效
PowerMockito.mockStatic(YouStaticClass.class);
MockitoAnnotations.initMocks(this);
}