3

I'm currently writing a csv-file-importer for my app, but I have difficulties writing tests for it. What I'm trying to do is import a sample csv file and compare the results to the database.

public class CSVImportTest extends ProviderTestCase2<MyProvider> {

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        mContentResolver = getMockContentResolver();
        setContext(new IsolatedContext(mContentResolver, getContext()));
        mContext = getContext();
        mCSVImport = new CSVImportParker(mContext);

    }

    public void read() {
        try {
            // Fails here with "File not found."
            InputStream input = mContext.getResources()
                 .openRawResource(my.package.R.raw.file);

            ...
        } catch (Exception e) {
            e.printStackTrace();
            fail();
        }

        ...
    }

}

The test file is never found, although it is available at the correct location.

prakt
  • 41
  • 4

1 Answers1

0

The issue is that resources in the raw directory are compressed unless they have an ogg or mp3 file extension. See this description:

Proguard breaking audio file in assets or raw

and from the docs

This function only works for resources that are stored in the package as uncompressed data, which typically includes things like mp3 files and png images.

So, the easiest way to solve the issue is by adding the mp3 or ogg file extension to your raw assets. It's not clean or pretty but it works.

Community
  • 1
  • 1
Michael
  • 703
  • 1
  • 5
  • 11