How can I find out if code is running inside a JUnit test or not?

前端 未结 11 1280
梦毁少年i
梦毁少年i 2020-12-24 10:34

In my code I need to do certain fixes only when it is run inside a JUnit test. How can I find out if code is running inside a JUnit test or not? Is there something like JUni

11条回答
  •  攒了一身酷
    2020-12-24 10:45

    If you're doing things differently because you're doing a unit test you're defeating the purpose of a unit test. A unit test is supposed to perform exactly like production would (except for the setup and teardown of any necessary data and such you need....but that is included in the JUnit test itself and not your code).

    However, if you truly do have a good reason for this I'd look at the stack and see if JUnit is there.

提交回复
热议问题