Read file in fragment in junit test [message #1237729] |
Thu, 30 January 2014 12:45 |
|
Hey all,
i´m not sure if this is the right thread, but i couldn´t find a better one.Ok here is my problem:
Assuming i have the following test fragment structure:
my.fragment
|
|-src
| |-my.package
| |-MyTest
|
|-testData
| |-test.png
How can i access the "test.png" file in my junit test?
Note that i want to do a PURE junit test, no plugin test, so get the location from the bundle via an Activator is not possible. Also FileLocator can´t be used because i don´t want to have a dependency on eclipse.runtime.
Right now i´m using getClass().getResource() but this works only if my "test.png" file is located in a java package.
Thanks alot and greetz
Thomas
|
|
|
Re: Read file in fragment in junit test [message #1240057 is a reply to message #1237729] |
Wed, 05 February 2014 16:03 |
Henno Vermeulen Messages: 126 Registered: July 2009 |
Senior Member |
|
|
One way to do this by making the "testData" directory a source folder and let it's contents get copied to the same output folder as the classes. Then load it by using getClass().getResource("/test.png") where it is important to not forget the /
(Note that Maven uses the same approach: resources are put into src/main/resources which is added as a source folder to the project.)
[Updated on: Wed, 05 February 2014 16:05] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02552 seconds