mercredi 26 août 2015

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 void print(List<Item> items) {
        for (Item item: items){
            System.out.println("Name: " + item.getName());
            System.out.println("Number: " + item.getNumber());

        }
    }

currently, my test looks like this

@Test
    public void printTest() 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.

Aucun commentaire:

Enregistrer un commentaire