java - Capture Console Display (both input & output) -


i'm setting test cases console-based application in java. below code:

bytearrayinputstream in = new bytearrayinputstream("input 1\ninput 2".getbytes()); system.setin(in); //feeds inputs  bytearrayoutputstream out = new bytearrayoutputstream(); system.setout(new printstream(out)); //captures output  testprogram.test();  string output = out.tostring(); system.setout(new printstream(new fileoutputstream(filedescriptor.out))); system.out.println(output); 

the application simple , forth between console , user - console asks question, user gives answer. so, example, console might following @ end of interaction, given inputs above:

please enter color: input 1 please enter name: input 2 

...where input 1 , input 2 user's inputs, , prompts issued print commands testprogram.test().

i capture console looks @ end of interaction (i.e., both inputs , outputs together), seems can capture input , output independently. how can modify code above capture resulting console display, inputs , outputs appropriately woven together?

you log input , output in array , push them together.

i don't understand 100% can store them in array.

string[] s = (out.tostring() + in.tostring()).split("\n"); for(string : s) system.out.println(a); 

hope helps


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -