From: Janette W. <ja...@ca...> - 2006-04-03 20:20:53
|
Hi, my apologies if this question appears twice... I sent it once to the mailing list and found out I have to subscribe to the list first. So I subscribed and here's my question again. My question is on testing a couple of Strings sent to the console. e.g. I have this method: public static void usage() { System.out.println("Usage: BookStoreServer employeeID [seed]"); System.out.println("where employeeID is from E0000 to E9999"); } The usage() method is called under some circumstances. I wrote a JUnit test (see snippet below). When StartServer.main() is called with 3 arguments, it should cause the usage() method above to be invoked and output messages to the console. Question is, I don't know how to use assertEquals() or other means to check that those message have indeed been sent to the console. public void testStartServerNumOfArgsMoreThanUpperBound(){ String[] argsArray = {"E0001", "1234", "invalid3rdArgument"}; StartServer.main(argsArray); //assertEquals("Usage: BookStoreServer employeeID [seed]"); // Have to figure out how to assert the output from usage() } Appreciate any guidance, thanks. Janette Wong |