One of the JUnit best practices is : same package, separate directories. I am wondering what开发者_如何学编程 is the equivalent for Mock classes ? Do you keep them in the same package as classes they are supposed to mock, but in the test directory ? or elsewhere ?
Like many things in programming, "it depends." Here are some rules of thumb I use:
- If I have a stub that is only used by one test and is small - create an inner class
- If I have a stub that is only used by one test and is large - put in same package/folder as test
- If I have a stub that is used by multiple tests in the same package - put in same package/folder as test
- If I have a stub that is used in many places in the same application - put in a test.util package
- If I have a stub that is used across applications, put it in a jar.
I have instances of all of these in my code.
精彩评论