Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Read file in fragment in junit test
Read file in fragment in junit test [message #1237729] Thu, 30 January 2014 12:45 Go to next message
Thomas Wilhelm is currently offline Thomas WilhelmFriend
Messages: 28
Registered: September 2013
Junior Member
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 Go to previous message
Henno Vermeulen is currently offline Henno VermeulenFriend
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

Previous Topic:Bundling web browser with RCP app
Next Topic:How to implement save on an IEditorPart
Goto Forum:
  


Current Time: Fri Mar 29 12:57:29 GMT 2024

Powered by FUDForum. Page generated in 0.02552 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top