Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JUnit Eclipse show System.out.print()'s

I am using JUnit 3 with Eclipse 3.4. When I run a JUnit test case everything works fine and the test completes perfectly. Only thing is I want to see the output of the classes that I am running. All the classes have basic System.out.print() to some output values. So when I run the tests I don't see any console messages at all. How do I get Eclipse to show System.out.print() output in Console window when a test is successful?

like image 946
JPM Avatar asked Feb 15 '11 07:02

JPM


People also ask

How can you use JUnit for testing a code that throws a desired exception?

JUnit provides an option of tracing the exception handling of code. You can test whether the code throws a desired exception or not. The expected parameter is used along with @Test annotation. Let us see @Test(expected) in action.

How do you call a method in JUnit test case?

Create Test Runner Class It imports the JUnitCore class and uses the runClasses() method that takes the test class name as its parameter. Compile the Test case and Test Runner classes using javac. Now run the Test Runner, which will run the test case defined in the provided Test Case class. Verify the output.

How do you test a function in JUnit?

A JUnit test is a method contained in a class which is only used for testing. This is called a Test class. To define that a certain method is a test method, annotate it with the @Test annotation. This method executes the code under test.


2 Answers

Maybe other program was running on the console of Eclipse too. Please ensure Eclipse displays the active view of your JUnit code.

From Eclipse Help:

Select the “Display Selected Console” command to bring the console selected from the resulting list into focus. Note: this command is only enabled if you have more than one console open.

like image 103
卢声远 Shengyuan Lu Avatar answered Sep 22 '22 13:09

卢声远 Shengyuan Lu


jUnit does not suppress System.out statements. If the statement is hit during the test run, then it is executed and writes to System.out which is, when executed within eclipse (Run Configuration), the console window.

But maybe you've redirected System.out to write to a file or a log.

like image 20
Andreas Dolk Avatar answered Sep 21 '22 13:09

Andreas Dolk