Separation of JUnit classes into special test package?

后端 未结 3 1413
萌比男神i
萌比男神i 2020-12-04 06:24

I am learning the concepts of Test-Driven Development through reading the Craftsman articles (click Craftsman under By Topic) recommended in an answer to m

3条回答
  •  有刺的猬
    2020-12-04 07:23

    I use Maven. The structure that Maven promotes is:-

    src/main/java/org/myname/project/MyClass.java
    
    src/test/java/org/myname/project/TestMyClass.java
    

    i.e. a test class with Test prepended to the name of the class under test is in a parallel directory structure to the main test.

    One advantage of having the test classes in the same package (not necessarily directory though) is you can leverage package-scope methods to inspect or inject mock test objects.

提交回复
热议问题