0
votes

I run my tests using maven surefire plugin. When I need to debug the code, I use
mvn -Dmaven.surefire.debug test to redirect to eclipse debugger.

This works well, but the log statements are not redirected to eclipse console. Is there anyway we can redirect log and System.out statements to eclipse console view.

I tried setting useFile=false and maven.test.redirectTestOutputToFile=false properties. These options don't seem work.

1
Why are you calling the command line if you like to run unit tests in Eclipse? Just start the unit test from Eclipse and the logging output will be put into eclipse console. - khmarbaise
Eclipse uses M2E plugin which is different from actual maven installation. I have multiple projects in my workspace, so M2E plugin doesn't work consistently for build and test cases. However, build and test cases work fine in command line. Seems like lot of people face issues with M2E plugin and the recommended approach is to with command line. - Naresh Vavilala
@NareshVavilala You can define an external Maven via Window → Preferences → Maven → Installations in Eclipse. - Gerold Broser
@NareshVavilala My previous comment was just meant to address your first comment not your original question. If I run a Run Configuration of type Maven Build with test goal and a Parameter maven.surefire.debug=true and if I connect to that with a Debug Configuration of type Remote Java Application both System.out.println(...) and Logger.info(...) are printed to my Eclipse's Console view. - Gerold Broser
thanks for your comment. Yes. log statements do get printed if I run the maven build in eclipse. but i face many other issues with eclipse build and tests, so i am looking for a way to redirect logging from maven command line to eclipse console - Naresh Vavilala

1 Answers

1
votes

You can call any commandline process from eclipse by adding it as an External Tool.

First, open the external tools dialog:

External Tools Configurations...

Then, add a new tool...

Add a new tool

And configure it to do what you want

Configure it to call maven

You should then be able to start your test from the external tools menu, and have all of the output directed to the Eclipse console.

Run External Tool from menu