[英]Is there a way to view all the paths through a method in IntelliJ IDEA?
I'm writing unit tests for a Java method which contains nested if statements. 我正在为包含嵌套if语句的Java方法编写单元测试。 I want to write a test for each path through the method.
我想通过该方法为每条路径编写一个测试。 However, I'm finding it hard work to identify all the paths.
但是,我发现找出所有路径都很困难。
Here's an example method through which there are three paths: 这是一个有三条路径的示例方法:
public void myMethod(int i) {
if (i % 2 == 0)
System.out.println("foo");
else {
if (i % 3 == 0)
System.out.println("bar");
else
System.out.println("baz");
}
}
For this method, I'd want an output something like: 对于这种方法,我想要一个类似的输出:
if (i % 2 == 0)
->
System.out.println("foo");
if (i % 2 == 0)
->
System.out.println("foo");
if (i % 2 == 0)
->
if (i % 3 == 0)
->
System.out.println("bar");
if (i % 2 == 0)
->
if (i % 3 == 0)
->
System.out.println("bar");
if (i % 2 == 0)
->
if (i % 3 == 0)
->
System.out.println("baz");
if (i % 2 == 0)
->
if (i % 3 == 0)
->
System.out.println("baz");
Does a feature like this exist in IntelliJ IDEA? IntelliJ IDEA中是否存在这样的功能? And if not, is there another tool that'll do the job?
如果没有,还有另一种工具可以完成这项工作吗?
运行覆盖测试(在调试图标旁边),然后您可以看到您已覆盖的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.