cdczc
cdczc

Reputation: 15

How to use image in android test from src/test/resources dir

I am trying to use the image present inside src/test/resources for unit testing a functionality

@RunWith(AndroidJUnit4.class)
public class OcrHelperInstrumentedTest {

    @Test
    public void testLoadImageFromFile() throws IOException {
        // Load the image from test resources
        File file = new File(getClass().getClassLoader().getResource("1.png").getFile());

        // Create a Uri from the File*
        Uri fileUri = Uri.fromFile(file);

        // Use the file Uri with InputImage
        InputImage inputImage = InputImage.fromFilePath(ApplicationProvider.getApplicationContext(), fileUri);

        // Assert the input image is loaded correctly
        assertNotNull(inputImage);
    }

but I am getting an error:

java.io.FileNotFoundException: /file:/data/app/com.example.regiscan.test-VXJWGppk-9KqdmtyGKtCvg==/base.apk!/1.png: open failed: ENOENT (No such file or directory)

Does anyone has any suggestions on how to fix it ?

Upvotes: 0

Views: 24

Answers (0)

Related Questions