2

Scenario:

I have a JUnit test with SysOut calls. I want to suppress these calls when maven is executing in order to reduce clutter on the screen. However, I'd still like it to print out when run through Eclipse.

Is there a way to check programmatically if the Maven is the one executing the JUnit test?

Pseudo-code:

if (!isCalledByMaven()) {
    System.out.println("Bob is not here.");
}
Community
  • 1
  • 1
ScrappyDev
  • 2,307
  • 8
  • 40
  • 60
  • 4
    Changing code and test behaviour depending on the environment sounds like a bad idea: https://github.com/auchenberg/volkswagen . – luk2302 Nov 01 '17 at 15:55
  • Or maybe execute maven with `-q` for not logging everything. – Naman Nov 01 '17 at 16:09
  • Wrap in a class and inject a mock? –  Nov 01 '17 at 16:25
  • Maybe something like this could help https://stackoverflow.com/q/3776204/3124333 ? – SiKing Nov 01 '17 at 17:50
  • If I were changing the behavior of the test, I would agree luk2302, but I'm not. I've left the asserts alone. The SystemOuts do no validation, they are simply useful for debugging and gauging status. I'm more looking for something that is in the properties/session that I can use as a switch. – ScrappyDev Nov 01 '17 at 18:05
  • @ScrappyDev Sounds like trying to keep profiles with different logging levels and executing default with IDE while any specific with a command line. Not very convincing to why though. – Naman Nov 01 '17 at 18:24
  • Having a unit tests with System.out.println which are a kind of assertion...it does not make sense..either you check the output being printed out via real assertions or you are doing something wrong...See http://stefanbirkner.github.io/system-rules/ – khmarbaise Nov 02 '17 at 10:03
  • I am fully aware of standards. I'm not asking about standards. I have a different purpose for this. I'm asking how to do this, not if I should. – ScrappyDev Nov 02 '17 at 21:55

0 Answers0