Gregg
Gregg

Reputation: 35864

Relative Path to Grails test Directory

I created a folder under the test directory to store some files needed for our tests. How can I access this directory via a relative path? I looked into the GrailsResourceUtils but it seems to only deal with the grails-app directory.

For example, I need to access something like:

test/artifacts/file.txt

Upvotes: 1

Views: 1306

Answers (2)

Dónal
Dónal

Reputation: 187529

Personally, I prefer to put test resources in the same directory as the test class(es) that use them. Then you can load the resource from the test class using

InputStream testResource = getClass().getResourceAsStream('file.txt')

or

URL testResource = getClass().getResource('file.txt')

Upvotes: 1

Gregg
Gregg

Reputation: 35864

Hm, it would seem this was as easy as that exact path:

new File("test/artifacts/file.txt")

resolves just fine.

Upvotes: 2

Related Questions