I like the maven convention: there is a separate source tree for the main and the test in one project, the main code is deployed, the test code is not. Package structures can be (but not necessarily) identical.
project src main java // source files resources // xml, properties etc test java // source files resources // xml, properties etc
And in eclipse, when you select new -> JUnit test case , you just change the source folder to src / test / java and leave the proposed package as it is.
(One of the benefits of the rest in the same package is access to protected and restricted element packages, although this is not the βcorrectβ unit test behavior)
Update: Here is the code illustrating my last point:
Main class (in src / main / java):
package com.test; public class Foo{ static class Phleem{ public Phleem(final String stupidParameter){ } } String bar; protected String baz; protected Object thingy; }
Testing class (in src / test / java):
package com.test; import org.junit.Test; public class FooTest{ @Test public void testFoo(){ final Foo foo = new Foo(); foo.bar = "I can access default-scoped members"; foo.baz = "And protected members, too"; foo.thingy = new Foo.Phleem("And I can access default-scoped classes"); } }
Sean Patrick Floyd Aug 26 2018-10-10T00: 00Z
source share