1
我正在尝试使用我的APP测试文件操作。首先,我想检查一下,无论何时我调用读取文件的函数,该函数都会抛出异常,因为文件不在那里。Android JUNIT文件操作测试
但是,我似乎不明白如何实现这...这是我设计的代码,但它不运行...正常的JUNIT说没有找到FILEPATH,android JUNIT说,测试不能运行。
文件夹:/data/data/example.triage/files/是在虚拟设备已经上市...
@Before
public void setUp() throws Exception {
dr = new DataReader();
dw = new DataWriter();
DefaultValues.file_path_folder = "/data/data/example.triage/files/";
}
@After
public void tearDown() throws Exception {
dr = null;
dw = null;
// Remove the patients file we may create in a test.
dr.removeFile(DefaultValues.patients_file_path);
}
@Test
public void readHealthCardsNonExistentPatientsFile() {
try {
List<String> healthcards = dr.getHealthCardsofPatients();
fail("The method didn't generate an Exception when the file wasn't found.");
} catch (Exception e) {
assertTrue(e.getClass().equals(FileNotFoundException.class));
}
}
SetUp不会生成异常...它只是创建对象的新实例即时检查.. – OHHH 2014-11-08 21:55:59
好吧完美。我会在'setup()'方法中移除'throws Exception'标记,然后你不需要它。重写'tearDown()'是否修复了JUnit问题? – 2014-11-08 22:12:26
我意识到问题在于测试的工作方式......为了测试Android应用程序的行为,您需要一个新的应用程序来打开待测试应用程序并分析变量。我通过为此创建一个新项目来解决问题。 – OHHH 2014-11-09 02:11:52