How to use this.getClass.getResource from a test #2252
Closed
alexklibisz
started this conversation in
Education
Replies: 2 comments
-
@alexklibisz Thanks for opening discussion, This is a bug that was fixed #2235. As a workaround, you can use the resourceDir directive in your sources, but it also include resources into
Alternatively, you can test the fixed version by running the nightly version of scala-cli:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Confirming that this works with the nightly. Thanks! $ scala-cli --cli-version nightly test .
Fetching Scala CLI 1.0.1-44-g92f069c1-SNAPSHOT
Compiling project (Scala 3.3.0, JVM)
Compiled project (Scala 3.3.0, JVM)
Downloading 2 dependencies and one internal dependency
Compiling project (test, Scala 3.3.0, JVM)
Compiled project (test, Scala 3.3.0, JVM)
Test:
file:/Users/alex/Desktop/scala-cli-resources/.scala-build/scala-cli-resources_0d8cb35018_98f7a0bcf5/classes/test/app/test.txt
null
null
file:/Users/alex/Desktop/scala-cli-resources/.scala-build/scala-cli-resources_0d8cb35018_98f7a0bcf5/classes/test/app/test.txt
null
null
- getResource
Run completed in 217 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using SBT, I have generally used
this.getClass.getResource
to access files from theresources
directory within tests. This doesn't seem to work with scala-cli.Here's a small example project:
I try to access the test.txt resource several ways, and all of them return null.
I've also tried different settings of
test.resourceDir
, but get the same result.Beta Was this translation helpful? Give feedback.
All reactions