Accessing resources in an android test project

后端 未结 4 1161
天涯浪人
天涯浪人 2020-12-06 10:06

I have setup an android test project that runs junit tests. It\'s using two eclipse projects \"Application\" and \"ApplicationTest\" where my tests are in the \"ApplicationT

4条回答
  •  眼角桃花
    2020-12-06 10:27

    I derived the test case as follows:

    class MyTest extends InstrumentationTestCase {
        void setUp() {
            InputStream is = getInstrumentation().getContext().getAssets()
                .open("test_image.bmp");
            ...
       }
    }
    

    And the file test_image.bmp is saved in assets directory, which is reasonable if you intend to use the asset for some testing related work - and its not part of ui resources. The technique is used in another context here: https://stackoverflow.com/a/4570206/1577626

提交回复
热议问题