Saturday, August 10, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...