java - 如何使用 Junit 和 mockito 为这个类编写单元测试?
问题描述
下面是我想使用 Junit 和 Mockito 编写单元测试的课程。我无法做到这一点。
该接口加载一个本地库,然后使用类方法调用本地库方法。我需要通过模拟本机库方法来为这些方法编写单元测试。我发现这很棘手,因为使用 InterfaceA.INSTANCE.method1() 调用了本机方法。我如何嘲笑它?
package x.x.x;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
public class ClassB {
public interface InterfaceA extends Library {
InterfaceA INSTANCE = (InterfaceA) Native.load("ClassA.api", InterfaceA.class);
int interfaceMethod1();
int interfaceMethod2(String string1);
}
public boolean method1(){
int result = InterfaceA.INSTANCE.interfaceMethod1();
return result != 0;
}
public boolean method2(String string1){
int result = InterfaceA.INSTANCE.interfaceMethod2(string1);
return result != 0;
}
}
解决方案
推荐阅读
- java - Java NIO SelectionKey.attachment() 在取消时释放
- javascript - 是否可以在 Vert.x 中使用 Javascript 库?
- python - sklearn 的 metrics.accuracy_score 的结果似乎是错误的
- c - 使用 fscanf 读取整数时遇到问题
- android - Java 安卓 | 在通话中以编程方式使用通话中的数字键盘
- php - Wordpress ajax-admin.php 等待时间太长
- regex - Postgresql 替换所有出现的字符串+
- sql-server - 当 current_value 与使用它的表行不同步时更新 SQL Server 中序列的 current_value
- c# - 代表处理二维数组中的任何更新
- javascript - 从另一个数组中获取第一个数组的属性长度