开发者

Where do you keep your Stubs?

开发者 https://www.devze.com 2023-01-08 09:10 出处:网络
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

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:

  1. If I have a stub that is only used by one test and is small - create an inner class
  2. If I have a stub that is only used by one test and is large - put in same package/folder as test
  3. If I have a stub that is used by multiple tests in the same package - put in same package/folder as test
  4. If I have a stub that is used in many places in the same application - put in a test.util package
  5. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消