Test resources directories

sbt

(Rania Chantzopoulou) #1

Hello,

I inherited a project with Play 2.5.4 and I am trying to separate their unit and integration tests, so I moved all tests with database to an “it” folder

I am having an issue with the configuration of resources

rania@xx:~/projects/yy$ sbt test:resource-directory
[info] Loading global plugins from /home/rania/.sbt/0.13/plugins
[info] Loading project definition from /home/rania/projects/yy/project
[info] Set current project to yy (in build file:/home/rania/projects/yy/)
[info] /home/rania/projects/yy/test/resources

rania@xx:~/projects/yy$ sbt it:resource-directory
[info] Loading global plugins from /home/rania/.sbt/0.13/plugins
[info] Loading project definition from /home/rania/projects/yy/project
[info] Set current project to yy (in build file:/home/rania/projects/yy/)
[info] /home/rania/projects/yy/src/it/resources

So in the case of the it tests, it is taking the default sbt path “src/it/resources” whereas for the normal tests it is “test/resources”. How can I solve this?

I don’t have any relevant config about the resources in build.sbt, this looks like the default behavior


(Rania Chantzopoulou) #2

So this is the solution that worked, I added in build.sbt

    resourceDirectory in IntegrationTest := (baseDirectory apply {baseDir: File => baseDir / "it/resources"}).value

Any comments or improvements are welcome


(Marcos Pereira) #3

Hi @rania,

This looks like a more idiomatic way to solve that:

https://www.scala-sbt.org/1.0/docs/Howto-Customizing-Paths.html#Add+an+additional+resource+directory

You will then have:

unmanagedResourceDirectories in IntegrationTest += baseDirectory.value / "it" / "resources"

So that you won’t completely override the setting, but instead just compose with the existing one.

Best.