cmdematos
cmdematos

Reputation: 913

How to tell if called from JUnit?

I think that a piece of code under test should not know that it is under test. Therefore, this question represents an anti-pattern, but I have a need to configure a legacy application in a particular way 'if called from a JUnit integration test'. If you think that this smells like an application that does not use CDI you are correct.

I can always walk the stack to see if I was called from JUnit. I am hoping for something more elegant.

Upvotes: 1

Views: 57

Answers (1)

Stefan Birkner
Stefan Birkner

Reputation: 24540

How about using a system property that is set by the JUnit test, evaluated by the class under test and resetted by JUnit afterwards?

Upvotes: 2

Related Questions