How to set Unit Test to Fragment in Android

后端 未结 4 1272
梦如初夏
梦如初夏 2020-12-23 14:10

I want to unit test an Android Fragment class.

Can I set up a test using AndroidTestCase or do I need to use ApplicationTestCase?

Are there any useful exampl

4条回答
  •  执念已碎
    2020-12-23 14:31

    I'm pretty sure you can do what you're saying, create a mock Activity and test the fragment from there. You just gotta export the compatibility library in the main project and you'll be able to access the fragments from the test project. I'm gonna create a sample project and test the code here and will update my answer based on what I find out.

    For more details on how to export the compatibility library, check here.

提交回复
热议问题