3

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:

  1. PrintStream out = System.out; System.setOut(out); System.out.println("hello");
  2. Eclipse Console not showing output
  3. Explicitly throw an exception (resulted in no stack trace in console)
Sintrias
  • 456
  • 1
  • 9
  • 19
  • i would guess it doenst get executed, are you sure its running your java code – Henning Luther Dec 05 '18 at 15:56
  • I am. I have a very exhaustive test script with a rather large custom code class that wraps a lot of Selenium and the custom code is doing what I want it to do except for wherever there is a System.out.println() or System.err.println(). – Sintrias Dec 05 '18 at 16:07

2 Answers2

3

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

enter image description here

Sintrias
  • 456
  • 1
  • 9
  • 19
  • 1
    Great that you found the solution! I suggest that you mark this answer as accepted so that people know it has been answered. – Konrad Höffner Dec 06 '18 at 13:57
  • Thanks. I'd like to, but Stack Overflow tells me I have to wait 18 more hours. Which is fine I guess. Probably some rank I have to reach first to get rid of that. – Sintrias Dec 06 '18 at 20:28
  • 1
    This is only valid on Windows. – MiB Mar 16 '21 at 11:29
  • Thanks for the clarification @MiB. I have never owned a system other than a Windows system. – Sintrias Mar 28 '21 at 22:45
0

Does it work in an unrelated project in Eclipse but not your current project? I assume some of the library code you use calls System.setOut() (and Err analogously) to change the print stream. What you can try is:

PrintStream out = System.out;
...
insert your library calls here
....
System.setOut(out);
System.out.println("Test out println");
Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118
  • Well, I gave that a shot and still nothing. I also created a new project without any dependencies and just a main function and STILL nothing. It's so weird. Maybe it's my Eclipse. – Sintrias Dec 05 '18 at 15:59
  • I was able to verify in debug mode that the System.out is not being changed. The Eclipse console is literally just not putting out any data. – Sintrias Dec 05 '18 at 16:29
  • Just tried Run > Run Configurations > Common then linked external file to redirect output to. I then executed the main method again and the file never receives any data. – Sintrias Dec 05 '18 at 16:41