java - 功能接口单元测试
问题描述
您如何测试使用功能接口的类。那么我如何测试下面的两个具体类:
@FunctionalInterface
public interface Test {
int sumTwoValues(int x, int y);
}
public class UseTestExample {
public int useTest(int z, Test test) {
int returnValue = test.sumTwoValues(z, 10);
return returnValue;
}
}
public class MainTest {
public void clientCall() {
UseTestExample testExample = new UseTestExample();
testExample.useTest(10, (x,y) -> {
return x+y;
});
}
}
我可以看到 UseTestExample,我可以在单元测试期间传入一个实现并检查我返回的内容是否正确?
但是 MainTest 类,我怎么能测试呢?
解决方案
推荐阅读
- sql - 重新排序 SQL 数据(足球数据)
- vue.js - 如何在 VueJS 中的 window.onpopstate 中使用变量
- angular - Jasmine 测试:预期未定义等于 Object。(如何测试@input)
- java - 如何正确地使用负数?
- azure - Azure ARM 模板 - 处理 ARM 模板之间的依赖关系
- javascript - 如何在 Plumier 中不创建新的 DTO(数据传输对象)进行验证
- python - Dialogflow 和 Skype 集成 - 通过连接到 MySQL 数据库进行用户身份验证
- c++ - 在 C++ 中,为什么 int 可以使用 new 运算符初始化变量而 double 不能?
- reactjs - 在屏幕之间切换时出现“无法在未安装的组件上执行 React 状态更新”
- node.js - jwt令牌如何确保在数据库更改时更新有效负载