待测类(CreateString)如下: public class CreateString { public void createString() { //Output the following string "1 2 3" System.out.print("1 2 3\n"); //Output the following string "1 2 3" System.out.print("1 "+"2 &q
核心思路: 在测试前,将标准输出定向到ByteArrayOutputStream中去 用输出流文件断言内容 测试完成,将标准输出修改为console 具体操作示例 基本通用复制粘贴操作 public String sep = System.getProperty("line.separator"); public ByteArrayOutputStream out = null; @Before public void setUp() throws Throwable{ out = n