Sunday 24 December 2017

java - Trying to use Junit to verify console output matches a string

I'm trying to use Junit to verify that something output by
a method matches a string using assertequals, but I can't get it to work. Because it
says that the test case is undefined for (String, Void) My code for the method is
below




public void
speciesInformation() {
switch (species){


case"Penguin":System.out.println("Penguin Trivia fact");

break;

default: System.out.println("There is no current
information for that species");
break;
}

}



and
the junit code I'm attempting to use is(other tests
omitted):



public class AnimalsTest
extends junit.framework.TestCase{
public void testSpeciesInfo() {

assertEquals(" Penguin Trivia fact/n",
penguin.speciesInformation());
}
}



All
my other tests work because they're based on a return, but this one is supposed to be
based on what's printed by the public void method and I can't tell how to do it or find
information on how.

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...