Reputation: 2389
Introduction: Though the title looks duplicate to other stackoverflow questions i've already read it and not similar question.
Background:
I have created a maven project with package x.y.z
under src/main/java
and lot of classes inside of it let say classes A-Z. Only class A is defined as public class
. i have created another package a.b.c
and the only class that is accessible is class A
as expected.
Question: But why Test classes under src/test/java able to access all java classes inside package x.y.z
even classes defined as non public access modifier? How will i make this inaccessible to Test classes?
Thank you!
Upvotes: 1
Views: 213
Reputation: 13402
Your Test Classes are in the same package, which is x.y.z
. That is why they are directly accessible. It is just that, directory structure is different for test class not the base package, which they are part of.
Check you test classes package declaration must be package x.y.z
.
When we write the test cases, you always use the package to which the code class belong.
Upvotes: 1