- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是测试用例的新手,我尝试了多种方法为下面的代码编写测试用例,但从未成功。如何使用Powermockito为下面的代码编写junit测试用例?
StreamSupport.stream(irSet.spliterator(), false)
.filter(iResultRow -> iResultRow !=null)
.mapToInt(iResultRow ->{
String event = iResultRow.get("STF_TY_GH");
return StringUtils.isNotBlank(event) ? Integer.parseInt(event) : 1;
}).findFirst().orElse(1);
最佳答案
虽然使用一定量的模拟可以模拟每个调用,但我建议您使用另一种方法。
因此,您有一个由某些输入集 (irSet
) 变量生成的流。该流进行“一些”处理并返回一个整数结果。
所以如果你“想象”它是一个黑盒子:一种看起来像这样的函数:
int doSomething(Set<SomeRow> irSet) {
... your implementation is here...
}
在这种情况下,您可能希望通过提供各种输入集并期望一些输出来测试它的功能。如果输入中有 null
-s 怎么办?它会失败还是过滤掉需要的东西?如果集合为空怎么办?如果有 SomeRow
确实有 STF_TY_GH
数据怎么办,如果集合中没有这样的行怎么办?
以下是一个测试示例:
@Test
public void test_rows_with_null_are_processed_correctly() {
// setup:
Set<SomeRow> input = ...// prepare a set with null values
// when:
Integer actual = underTest.doSomething(input)
// then:
// verify this "actual" whether it should be 1 or something else
}
总而言之,仅将模拟用于交互(与您无法真正实例化的东西,如 DB API/远程 HTTP 调用)或与测试代码不相关并用作测试依赖项的东西代码交互。毕竟,单元测试的目标是测试您的代码(在本例中是 doSomething
的实现,而不是模拟所有内容)。
关于java - StreamSupport 的 Junit 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59025599/
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!