How to get, during test, file generated by sbt (resourceGenerators)?

Viewed 95

So I have this setting

(resourceGenerators in Test) += Def.task {
  val file = resourceManaged.value / "simplefolder" / "simplefile"
  IO.write(file, "Hello world!")
  Seq(file)
}.taskValue

And in some test I have

Source.fromResource("simplefolder/simplefile").mkString

I see that the file is created inside the target/scala-*/resource_managed folder, but still, I cannot using during the test, because that code throws an NullPointerException... What am I doing wrong there?

If the file were not created in the folder simplefolder it works, but when created inside another folder inside the resourceManaged.value folder, it doesn't work

1 Answers

Scope to Test throughout

val file = (Test / resourceManaged).value / "simplefolder" / "simplefile"

since show Test / managedResourceDirectories gives

.../target/scala-2.13/resource_managed/test

noting the test directory at the end.

Related