I am trying to understand the JUnit way of imports classes at test time.
I noticed that creating a mock class with the same name of a src class, and the same package, will cause a test to import that one instead of the real src class.
For example :
src/main/java/MyObject.java
src/main/java/ObjectPrinter.java
src/test/java/MyObject.java
src/test/java/ObjectPrinterTest.java
Where both the main/java/MyObject.java
and the test/java/MyObject.java
declares the same package (both files starts with the same package XXX
decleration).
The ObjectPrinter.java
(which is called by ObjectPrinterTest.java
at test time) will have an import XXX.MyObject
decleration.
How is it that in test time the import XXX.MyObject
will import the test/java/MyObject.java
and a 'production' call will call the src/java/MyObject.java
?.
Is this kind of directory building safe? Is it common usage?
Where can i read more about this specific flow?
Thanks!