<分区>
我尝试在 IntelliJ 中为修改字符串的应用程序编写 JUnit 测试。现在如何在控制台上测试一个特定的打印?
假设起始字符串作为“Hello World”存储在 args[0] 中,并且我们有一个方法可以更改字符串中的单个字母。方法执行后会打印出字符串。
public class modifyString {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(true) {
// Print the string
System.out.println(args[0]);
// Wait for a userinput that only contains two chars,
// e.g. '0h' <- 'Change the index 0 to 'h''
// (the order of the chars is unimportant)
String input = scanner.nextLine();
if(preconditionFullfilled(input)) {
executeOperation(input, args);
}
}
}
}
例如:在 args[0] 中带有“Hello World”字符串的输入“0h”的预期输出应该是“hello World”。
如何编写 JUnit 测试来测试这个特定结果?