I am working on "robotium with junit". I have come across the situation where, my code is not able to find the Xml file on the given path.(Provided that the specified path is correct).
If I run the same code(file reading) with normal java then its working fine.
But when i run the code with junit, code cannot find the specified Xml file.
Here is my 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 is the simple Java code which works fine for 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 i am having the xml file with me on the specified path, I am getting "file not found" message from else.
Is there any other way in junit, to access the file ?
Please help me to solve this issue. Where exaclty i am going wrong ?
Thanks in advance.