file.exists() returning false in Android unit test

110 views Asked by At

I am trying to test some file related logic in an Android unit test, but whenever I call file.exists() it always returns false for some reason. Here is a boiled down example of a test case I have:

 @Test
    fun `some test case`() {
        val file = File("/storage/emulated/0/Photo1234.jpg")
        assertTrue(file.exists()) // Fails
    }
}

Does anybody know what I'm doing wrong? I've also tried file.absoluteFile.exists() but that returns false also.

1

There are 1 answers

0
kc_dev On

I figured it out. I was not calling file.createNewFile().