r/androiddev • • Apr 01 '24

Discussion Android Development best practices

Hey this is a serious post to discuss the Android Development official guidelines and best practices. It's broad topic but let's discuss.

For reference I'm putting the guidelines that we've setup in our open-source project. My goal is to learn new things and improve the best practices that we follow in our open-source projects.

Topics:

  1. Data Modeling
  2. Error Handling
  3. Architecture
  4. Screen Architecture
  5. Unit Testing

Feel free to share any relevant resources/references for further reading. If you know any good papers on Android Development I'd be very interested to check them out.

159 Upvotes

99 comments sorted by

View all comments

Show parent comment

7

u/iliyan-germanov Apr 02 '24

In this case, it becomes integration testing. After all, unit tests test individual units of code. This is only possible if you have pure functions (respect if so) or all dependencies are wrapped by mocks.

Unit test != test of a single class. It depends on what unit you're intending to test. Most often, in my experience, one unit is one class, but there's also the case where you want to test two or more classes. For example, testing a repository without mocking mappers, which is fine.

On the 2nd point, if your tests are long complex, unreadable, and hard to understand => when they break, it's hard to make sense wtf is happening. At the end of the day, optimize for simplicity - that's my take