I am running instrumented tests for my code and I am trying to convert an image to byte array and then pass it in to a method, (the image is saved on a folder path in my test path). I am doing this in android Instrumented test because I need to pass in context to my method where I am using the byte array image. But I keep getting No such file exception,
java.nio.file.NoSuchFileException: app/src/androidTest/testImages/image_s.png
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.Files.readAllBytes(Files.java:3152)
When I click on the image path on the error log it opens the image on my IDE so I know for sure that I am not passing in a wrong path>
This is my sample code.
@Test
fun returnsValidationResultOnImagePassed() {
var image = File("app/src/androidTest/testImages/image_s.png")
var imgByte: ByteArray = Files.readAllBytes(image.toPath())
var imagePath = Base64.encodeToString(imgByte, Base64.NO_WRAP)
val result: ArrayList<ValidationResult> = processor.process(imagePath, context)
Log.d("tests", result.toString())
Assert.assertNotNull(processor)
}
I've also tried creating a file with the image path, convert to buffered Image then to byte array using Bytestream still result in file not found exception
Also search for solutions like trying this Error:Execution failed for task ':app:mockableAndroidJar'. > java.nio.file.NoSuchFileException: C\path\.android\.android\build-cache.
If anyone has links to a solution for this please also share.