Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » How to access TestData from headless build
How to access TestData from headless build [message #525271] Tue, 06 April 2010 00:27 Go to next message
Richard Adams is currently offline Richard AdamsFriend
Messages: 77
Registered: July 2009
Location: Edinburgh
Member
Hello,
In our SWTBot test plugin, we have a folder of Test Data that the test setups use to populate projects with data that can be used in the test. When running in the IDE this is great and in the test source code we can loadup files using a project relative path (e.g., new File ("TestData/mymodel.xml")

However when running headless in an exported product we have a problem in that these files cannot be accessed. They are included in the build, and the test plugin is unpacked, but the files cannot be read. Does anyone know how SWTBot test code can load up test data when the tests are being invoked headlessly and are embedded in an RCP app?

Thanks in advance,
Richard


Re: How to access TestData from headless build [message #525275 is a reply to message #525271] Tue, 06 April 2010 00:55 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
Hi Richard,

What we do is ensure that the file is actually packed as part of the
build and then get an inputstream for it using SWTBot's FileUtils class:

bundle = Platform.getBundle('com.example.bundle');
internalUrl = bundle.getEntry('/path/to/file.txt');
url = FileLocator.resolve(internalUrl);
inputstream = url.openStream();

contents = FileUtils.read(inputstream);

There are a few other utility methods in FileLocator that you may find
useful.

Cheers!

-- Ketan

On 4/5/10 5:27 PM, Richard Adams wrote:
> Hello,
> In our SWTBot test plugin, we have a folder of Test Data that the test
> setups use to populate projects with data that can be used in the test.
> When running in the IDE this is great and in the test source code we can
> loadup files using a project relative path (e.g., new File
> ("TestData/mymodel.xml")
>
> However when running headless in an exported product we have a problem
> in that these files cannot be accessed. They are included in the build,
> and the test plugin is unpacked, but the files cannot be read. Does
> anyone know how SWTBot test code can load up test data when the tests
> are being invoked headlessly and are embedded in an RCP app?
> Thanks in advance,
> Richard
Re: How to access TestData from headless build [message #525371 is a reply to message #525271] Tue, 06 April 2010 11:55 Go to previous messageGo to next message
Ralf Ebert is currently offline Ralf EbertFriend
Messages: 168
Registered: July 2009
Senior Member
Hi Richard,

> and the test plugin is unpacked, but the files cannot be read. Does
> anyone know how SWTBot test code can load up test data when the tests
> are being invoked headlessly and are embedded in an RCP app?

I'm putting such resources along with my test classes on the class path, because that's
the only way I'm aware of loading resources independently from OSGi, f.e.:

TestResources.getStream("somefile.txt");

---

public class TestResources {

public static InputStream getStream(String filename) {
return TestResources.class.getResourceAsStream(filename);
}

}

Greetings,

Ralf


--
http://www.ralfebert.de/blog/
http://twitter.com/ralfebert/
Re: How to access TestData from headless build [message #525446 is a reply to message #525275] Tue, 06 April 2010 15:35 Go to previous message
Richard Adams is currently offline Richard AdamsFriend
Messages: 77
Registered: July 2009
Location: Edinburgh
Member
Thanks, that absolutely did the trick.
Since our app expects files, we write the stream
to tmp files and then cache the tmp file so the names are consistent through all tests

Cheers
Richard


http://csbe.bio.ed.ac.uk/adams.php
http://richardadams606blog.blogspot.com/


Previous Topic:SWTBot Ant Build Time out
Next Topic:Would like to have relative searching based on Composite parent
Goto Forum:
  


Current Time: Tue Mar 19 04:23:34 GMT 2024

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

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

Back to the top