如何在Junit5中模拟调用私有方法?

问题描述 投票:0回答:1
Class A{
 public void testA(){
   // other codes
   priMethod();
   // other codes
 }

 private void priMethod(){
   // other codes
 }
}

我想测试testA方法,priMethod方法不是测试的重点,我想跳过它。有没有类似dothing().when()的方法?

我发现的都是 junit4 方法或不起作用的方法,但我想要一个 junit5 解决方案,因为我无法更改 junit 版本或源代码。

java junit junit5
1个回答
0
投票

无法使用 Mockito 模拟私有方法

他们的维基:https://github.com/mockito/mockito/wiki/Mockito-And-Private-Methods

© www.soinside.com 2019 - 2024. All rights reserved.