将数据写入System.in [英] Writing data to System.in

查看:304
本文介绍了将数据写入System.in的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用程序中,我们希望用户输入 Thread ,如下所示:

In our application, we expect user input within a Thread as follows :

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

我想在单元测试中传递该部分,以便我可以恢复线程执行其余部分的代码。如何从junit写入 System.in 中的内容?

I want to pass that part in my unit test so that I can resume the thread to execute the rest of the code. How can I write something into System.in from junit?

推荐答案

你想要做的是使用方法 http://download.oracle.com/javase/6/docs/api/java中的noreferrer> setIn() /lang/System.htmlrel =noreferrer> 系统 。这将允许您从junit将数据传递到 System.in

What you want to do is use the method setIn() from System. This will let you pass data into System.in from junit.

这篇关于将数据写入System.in的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆