Results 1 to 4 of 4
Thread: Junit tests with ant
- 04-25-2010, 11:15 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Junit tests with ant
Hello,
can anyone tell me how could I do unit tests with ant, so that unit test class files could load my .properties file.
My app works great in eclipse, tests and all, but when I am doing ant build, then it fails on unit tests, because it can not locate .properties file.
Myproject
---------+WEB-INF
------------------conf
----------------------+my.properties
------------------classes
------------------------+com.myproj.test.ConfTest.java
------------------------+com.myproj.Conf.Conf.java
------------------myfiles
------------------------+example.xml
Now when I run from eclipse I can get my.properties in Conf class easily.
Other classes get InputStreams to files from Conf class which is utility class.
When working with ant, then those paths don't work.
The only way I got my.properties file was to give path like:
String path = "../../../system.properties"
That means all files should come with "../../../example.xml"
But those paths won-t work in eclipse, only during ant building.
Please help me on this. How can I solve this?
- 04-26-2010, 12:29 AM #2
- 04-26-2010, 08:09 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
I call them from ant task.
ConfTest tests class named Conf which much reach .properties file.
- 04-26-2010, 10:25 AM #4
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Have you ever had that moment when you have tried to find a solution for 1 problem 2 days, and you slowly going nuts, laughing by yourself in the dark corner?
Well I just had one of those moments.
2 days of searching, testing, headache, frustration and the solution was dumb.
I could run Junit tests from ant task, but they failed because they couldn't load a properties file from directory - not found. Though in eclipse all was fine.
After 2 days, this is what saved me:
System.out.println(new File("myconf.properties").getAbsolutePath());
I say that the path doesn't start with /MyProject/build/...
But it was /MyProject/ant/build/...
So, the solution was, I just moved my ant build file to /MyProject directory
Now the thing works, because project paths apply now.
/MyProject/ant solution would have been define directories in my app
like ../build/
instead of just build/
Thanks for solving it! > No problem man.
Similar Threads
-
int Array Tests
By Suzanne1187 in forum New To JavaReplies: 16Last Post: 04-16-2009, 01:49 AM -
Remote Junit Tests
By lord.ec in forum EclipseReplies: 0Last Post: 12-09-2008, 08:15 AM -
Using ant to run JUnit tests
By racerxadam in forum Advanced JavaReplies: 0Last Post: 10-21-2008, 04:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks