Issue
I am developing a test automation script using Cucumber, Selenium, and JUnit in Java. To quickly detect any issues with my custom code, I am placing System.out.println("success")
and System.err.println("failure")
in certain places. The problem is that neither print to the console in Eclipse. I've done this hundreds of times all though not necessarily with these tools. I suspect either Cucumber or JUnit is the culprit, but I couldn't find anything confirming this after some Google queries.
I did see this:
System.out.println doesn't print anything inside eclipse console
But that isn't the problem. None of my consoles are displaying my println()'s.
UPDATE What I've tried so far:
PrintStream out = System.out; System.setOut(out); System.out.println("hello");
- Eclipse Console not showing output
- Explicitly throw an exception (resulted in no stack trace in console)
Solution
So it turns out there is a bug with the version of Eclipse I was using (Eclipse Oxygen). Typically, when running code in Eclipse, the code is executed as javaw.exe instead of java.exe. The difference between those two are ONLY that javaw.exe does not use the CMD console where as java.exe does use the CMD console. Usually Eclipse will execute with javaw since it has its own console, however there is a known bug with some Eclipse versions, perhaps just Oxygen, where Eclipse does not handle this properly so you need to make it use java instead. To do this:
Go to Run > Run Configurations > make sure the desired class with the main method is selected on the left > select JRE on the right > click Alternate JRE under the Runtime JRE section > select Alternate under Java executable and type "java" in the field > Apply
Answered By - Sintrias
Answer Checked By - Senaida (JavaFixing Volunteer)