Results 1 to 4 of 4
  1. #1
    questioner is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default 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?

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by questioner View Post
    How can I solve this?

    i've a question: do you call your junit tests from inside the main-method?

  3. #3
    questioner is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    I call them from ant task.

    ConfTest tests class named Conf which much reach .properties file.

  4. #4
    questioner is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    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

  1. int Array Tests
    By Suzanne1187 in forum New To Java
    Replies: 16
    Last Post: 04-16-2009, 01:49 AM
  2. Remote Junit Tests
    By lord.ec in forum Eclipse
    Replies: 0
    Last Post: 12-09-2008, 08:15 AM
  3. Using ant to run JUnit tests
    By racerxadam in forum Advanced Java
    Replies: 0
    Last Post: 10-21-2008, 04:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •