Showing posts with label file. Show all posts
Showing posts with label file. Show all posts
Thursday, August 10, 2017
Proper way to access file resources in junit tests
Proper way to access file resources in junit tests
As I was refactoring some JUnit tests recently I was reminded of an important fact on the proper way to read in a file.
In maven any file under
/src/test/resources is automatically copied over to /target/test-classes. So for example lets say I need to read in a wsdl in my test. So I place the wsdl in the resources folder: /src/test/resources/test.wsdl. Now at first it might be tempting to reference the file with the following code:
File testWsdl = new File("/src/test/resources/test.wsdl");
and this will actually work on a windows machine; but what about linux, cygwin, or even solaris. Your next improvement might be to replace the
/ with File.separator:
File testWsdl = new File(File.separator + "src" + File.separator + "test"
+ File.separator + "resources" + File.separator + "test.wsdl");
This still isnt the best solution which is presented below:
URL url = this.getClass().getResource("/test.wsdl");
File testWsdl = new File(url.getFile());
Using the classs resource will locate the file in the tests classpath, which happens to be
/target/test-classes. And this final solution will work on windows, linux, cygwin, and solaris.Available link for download
Saturday, April 8, 2017
Open RAR file on Ubuntu 10 10
Open RAR file on Ubuntu 10 10
RAR(Roshal Archive) is an archive file format and supports data compression,file spanning and error recovery.On Ubuntu 10.10 Maverick Meerkat RAR files can be open,unpacked or extracted by many applications e.g rar,7-Zip,PeaZip,unrar,winRAR.
Installing RAR Extractor in Ubuntu 10.10
Open Ubuntu Software Center and search for rar.Install RAR compression/uncompression tool but remember its a shareware software so you must have to register after ending the trial period of 40 days.To install RAR tool just click on the install button(located in right end) and wait for the installation to complete(you may have to authenticate yourself by entering your ubuntu login password).Thats All..Now you can select any RAR file and right click,then extract to the desired location.
Available link for download
Subscribe to:
Posts (Atom)