业务类:

public class OutDemo {

    public void print(String content) {
System.out.print(content);
} }

测试类:

public class OutDemoTest {

    private StringBuilder systemOutput;

    @Before
public void setUp() {
systemOutput = injectSystemOutput();
} @Test
public void testOut() {
OutDemo out = new OutDemo();
out.print("123");
Assert.assertEquals(systemOutput.toString(), "123");
} private StringBuilder injectSystemOutput() {
StringBuilder stringBuilder = new StringBuilder();
PrintStream outputPrintStream = new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
stringBuilder.append((char) b);
}
});
System.setOut(outputPrintStream);
return stringBuilder;
} }

TDD之断言验证System.out.print输出的更多相关文章

  1. python中print()函数的“,”与java中System.out.print()函数中的“+”

    python中的print()函数和java中的System.out.print()函数都有着打印字符串的功能. python中: print("hello,world!") 输出 ...

  2. 使用System.out.print/prilntln() 输出时存在的问题

    刚学习Java时第一个接触的method就是System.out.println() 方法.但是最近在使用它输出一些变量时出现了我不理解的现象,首先上代码: /* * * using method S ...

  3. 电信SDK Pay函数里面System.out.print 无输出消息

    private void Pay(HashMap<String, String> payParams){ System.out.print("----------Pay Dian ...

  4. 怎么在logcat中显示system.com.print中的打印信息

    在logcat中显示信息可以用Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 1.Log.v 的调试颜色为黑色的,任何消息都会输出: 2.Log.d的输出颜色是蓝 ...

  5. 关于System.out.println()与System.out.print("\n")的区别

    这是在写junit测试的时候发现的. import java.io.ByteArrayOutputStream; import java.io.PrintStream; public class Te ...

  6. Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)System.out.print与Log

    日常啰嗦 距离上一次更新博客有一段时间了,主要是因为最近有开发任务,另外,这段时间也在学习docker的相关知识,所以博客就没有继续写了,推荐一本书<Docker技术入门与实战>(第二版) ...

  7. System.out.print()执行顺序

    今天使用递归调用计算的时候发现一个很奇怪的问题 代码: public class practice20 { public static double nStep(double N) { if (N&l ...

  8. Spring+SpringMVC+MyBatis+easyUI整合优化篇(一)Java语言中System.out.print与Log的比较

    作者:13 GitHub:https://github.com/ZHENFENG13 版权声明:本文为原创文章,未经允许不得转载. 前言 距离上一次更新博客有一段时间了,主要是因为最近有开发任务,另外 ...

  9. System.out.print实现原理猜解

    我们往往在main中直接调用System.out.print方法来打印,但是其实就这简单的一步里面有很多的玄机,因为main是static的,所以只能调用static的函数,那么print是stati ...

随机推荐

  1. Python数据分析中Groupby用法之通过字典或Series进行分组

    在数据分析中有时候需要自己定义分组规则 这里简单介绍一下用一个字典实现分组 people=DataFrame( np.random.randn(5,5), columns=['a','b','c',' ...

  2. 新增存储用Parted分区并建LVM卷

    新增存储用Parted分区并建LVM卷 一,Parted分区 1,parted分区  www.ahlinux.com # parted /dev/sda GNU Parted 2.1 使用 /dev/ ...

  3. caffe-----silence layer 作用

    最近看到prototxt里面有silence这个层,好奇是干什么用的,而且看源码也出奇的简单: #include <vector> #include "caffe/layers/ ...

  4. java:Spring框架3(AOP,SSH集成Demo)

    1.AOP: Spring提供了4种实现AOP的方式: 1.经典的基于代理的AOP 2.@AspectJ注解驱动的切面 3.纯POJO切面 4.注入式AspectJ切面 aop.xml: <?x ...

  5. Python学习之协程

    8.8 协程 ​ 我们都知道线程间的任务切换是由操作系统来控制的,而协程的出现,就是为了减少操作系统的开销,由协程来自己控制任务的切换 ​ 协程本质上就是线程.既然能够切换任务,所以线程有两个最基本的 ...

  6. htc 手机

    是否解锁locked unlocked 然后刷入REC

  7. mysql——单表查询——聚合函数——示例

    ), km ), cj ) ); select * from score; ,); ,); ,); ,); ,); ,); ,); ,); ,); ,); ,); ,); ; 查询此同学的总成绩: ; ...

  8. 交换机安全学习笔记 第六章 IPV4 ARP攻击

    ARP欺骗攻击 常用工具:  dsniff(Linux/windows).ettercap(Linux/windows).cain(仅windows). ARP欺骗攻击的目的是嗅探发往某主机的所有IP ...

  9. [转帖]虚拟内存探究 -- 第二篇:Python 字节

    虚拟内存探究 -- 第二篇:Python 字节 http://blog.coderhuo.tech/2017/10/15/Virtual_Memory_python_bytes/ 是真看不懂哦     ...

  10. qDebug的用法

    qDebug用于在控制台输出调试信息,主要有以下几种用法. 1.类似c++的cout函数 QString str="world"; qDebug()<<"he ...