duplicate package objects in main and test

Viewed 659

I have a package object defined in both main and the test code tree as shown below. When I execute the program with sbt run the one in the main code tree takes effect. Whereas when I run the test cases (sbt test) the package object defined in the test code tree takes effect. For eg

src/main/scala/com/example/package.scala

package object core {
  val foo = "Hello World"
}

src/test/scala/com/example/package.scala

package object core {
val foo = "Goodbye World"
}

on sbt run the value of com.example.core.foo is Hello World. on sbt test the value of com.example.core.foo is Goodbye World

Is this just a quirk of SBT or is it a well defined scala/sbt trait?. I currently use this behaviour for dependency injection by defining my module bindings for production and test in their corresponding package objects. This is an advisable approach?

1 Answers
Related