How to setup a test resource correctly to read it in a Scala CLI project #3138
Closed
halloleo
started this conversation in
Using directives and cmd configuration options
Replies: 1 comment 4 replies
-
Not sure what could the problem be... here's what I just tested and works fine: //> using test.dep org.scalameta::munit::1.0.1
//> using test.resourceDir ./resources
package org.myorg.myproject.mypack.tests
import java.io.InputStream
class ResourceTests extends munit.FunSuite:
test("getResource"):
val inp: InputStream = getClass.getResourceAsStream("/testResource.txt")
assertNotEquals(inp, null) tree
# .
# ├── Example.test.scala
# └── resources
# └── testResource.txt
#
# 2 directories, 2 files
scala-cli test .
# Compiling project (test, Scala 3.5.0, JVM (17))
# Compiled project (test, Scala 3.5.0, JVM (17))
# org.myorg.myproject.mypack.tests.ResourceTests:
# + getResource 0.006s |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I use Scala CLI (and MUnit) in a small Scala 3 project
In a test I want to read a resource. Under the project root the resource is at the path:
The Scala file of the test to get the resource is at
And the file looks like this:
When I run the Scala CLI command
it picks up the test and runs it, but the test always fails, beacuse
inp
is null. So the test does not find the resource.I have tried as resource location
"testResource.txt"
(so without the leading slash) - to no avail.I also have tried to tell Scala CLI that
src/test/resources
is a resource directory by addingto
App.test.scala
, but the test results stay the same too.So, how can I correct this? How can my test find the resource when using Scala CLI's
test
command? Do I have to put the resource somewhere else?Thank you very much for any pointers!
Beta Was this translation helpful? Give feedback.
All reactions