Saturday 10 August 2019

unit testing - How to test a print method in Java using Junit

I have written a method that is printing output to a console. How should I test it?




public class PrinterForConsole implements Printer{



public void printResult(List items) {
for (Item item: items){
System.out.println("Name: " + item.getName());
System.out.println("Number: " + item.getNumber());

}
}
}



currently, my test looks like this



public class TestPrinter{
@Test
public void printResultTest() throws Exception {
(am figuring out what to put here)

}
}



I have read the solution at this post (thanks @Codebender and @KDM for highlighting this) but don't quite understand it. How does the solution there test the print(List items) method? Hence, asking it afresh here.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...