Not able to access Xml file when code is executed using Junit -


i working on "robotium junit". have come across situation where, code not able find xml file on given path.(provided specified path correct).

if run same code(file reading) normal java working fine.

but when run code junit, code cannot find specified xml file.

here code: refer public void test_insert();

import java.io.file; import java.io.ioexception;    import com.robotium.solo.solo; import com.rohit.databse_crud.dbreader; import com.rohit.databse_crud.insert_act;  import android.test.activityinstrumentationtestcase2; import android.util.log;  @suppresswarnings("unchecked") public class initialbuttontest extends activityinstrumentationtestcase2 {  private static final string launcher_activity_full_classname = "com.xyz.dat.splashactivity"; private static class launcheractivityclass; static {      try {         launcheractivityclass = class                 .forname(launcher_activity_full_classname);     } catch (classnotfoundexception e) {         throw new runtimeexception(e);     } }  public initialbuttontest() throws classnotfoundexception {     super(launcheractivityclass); }  private solo solo;  @override protected void setup() throws exception {     solo = new solo(getinstrumentation(), getactivity()); }  public void test_insert() {     string name="c:/users/marathe/x.xml";     file xmll=new file(name);     if(xmll.exists())     {         system.out.println("file found");     }     else     {         system.out.println("file not found");     } } 

here simple java code works fine me:

import java.io.file; public class testfile {  /**  * @param args  */ public static void main(string[] args) {     // todo auto-generated method stub      string name="c:/users/marathe/x.xml";     file xmll=new file(name);     if(xmll.exists())     {         system.out.println("file found");     }     else     system.out.println("file not found");   }  }   o/p : file found 

though having xml file me on specified path, getting "file not found" message else.

is there other way in junit, access file ?

please me solve issue. exaclty going wrong ?

thanks in advance.

i store sample data want use in tests in res/raw folder. can read data in tests following:

private string getfiledata() throws exception {         writer writer = new stringwriter();         inputstream = null;         try {             = getinstrumentation().gettargetcontext().getresources().openrawresource(r.raw.sample_data);             reader reader = new bufferedreader(new inputstreamreader(is, "utf-8"));             int n;             char[] buffer = new char[1024];             while ((n = reader.read(buffer)) != -1) {                 writer.write(buffer, 0, n);             }         } {             if (is != null) {                 is.close();             }         }          return writer.tostring();     } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -