[英]code coverage of CompletableFuture.supplyAsync code
CompletableFuture.supplyAsync(() -> { }
我在CompletableFuture.supplyAsync(() -> { }
中有 10 行代码 CompletableFuture.supplyAsync(() -> {
// line 1
// line 3
..
..
..
// line 10
}
Without the awareness of the actual test case.没有实际测试用例的意识。 What you can possibly do to improve the code is to abstract those 10 lines of code to a method with can be then be called from the supplier.您可以做的改进代码的方法是将这 10 行代码抽象为一个方法,然后可以从供应商处调用。
This would give you an ease of testing the method separately without even calling the CompletableFuture.supplyAsync(...)
line as used in the code.这将使您可以轻松地单独测试该方法,甚至无需调用代码中使用的CompletableFuture.supplyAsync(...)
行。
For example, consider this abstraction例如,考虑这个抽象
CompletableFuture.supplyAsync(() -> supplyingMyValue());
where the supplyingMyValue
method exists such as存在supplyingMyValue
方法的地方,例如
Value supplyingMyValue() {
// perform some logic
return new Value();
}
and now you can test this method independently .现在你可以独立测试这个方法了。
Note : The solution hereby would still not test the supplyAsync
capability, but provide a way to test only the code invoked.注意:此解决方案仍然不会测试supplyAsync
功能,而是提供一种仅测试调用代码的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.