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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With