 <p>To unit test a code, that piece of code needs to be testable. </p> <p>To unit test a method, what we do is pass in some known input and check it is returning expected result or if we are having correct side effect. </p> <p>Now if you directly take your input inside your method, it is not very testable. It has two parts, reading the input and processing it. If the assert in your test fails, you don't know which step failed. Unit test should be aimed towards testing a unit or single responsibilty of a code.</p> <p>To make it testable, read the input in main method and pass it to another method for processing (also common notion of object oriented programming), and test the second method with known parameters.</p>