Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Take a stab at test friendly architecture

Take a stab at test friendly architecture

Look at the patterns and principles that help improve your application code, see how dependency injection fits in, and how easy tests are just a side effect of your clean architecture.

Ba3103b391ab5488fe5ee1dab37923ab?s=128

Brian Gardner

July 13, 2017
Tweet

More Decks by Brian Gardner

Other Decks in Technology

Transcript

  1. Take a stab at test friendly architecture Brian Gardner

  2. Goals • Principles & Patterns • Where DI can help

    • Testing setup
  3. Quick Pit Stop

  4. Sample Application

  5. List Screen Dependencies

  6. Create Screen Dependencies

  7. Cleaner Architecture Patterns

  8. Single Responsibility Principle

  9. Do one thing and do it well

  10. Smaller api == smaller tests

  11. UI Architecture Selection • MVC • MVP • MVVM •

    VIPER
  12. Sample Architecture

  13. Bias Towards Interfaces Composition vs Inheritance What it does vs.

    what it is
  14. Example Refactor

  15. Finding an interface instead of using a concrete class helps

    with testing
  16. Explicit Dependencies

  17. Implicit Dependencies

  18. Implicit Dependencies

  19. Explicit Dependencies

  20. Recap • SRP • UI Architecture • Bias Towards Interfaces

    • Explicit Dependencies
  21. Dependency Injection

  22. Dagger Recap

  23. Dagger Recap

  24. Dagger recap

  25. Dagger recap

  26. Applying the tools

  27. Single Responsibility Principle

  28. Doesn’t really help here

  29. Apply SRP to Dependency Injection

  30. Apply SRP to Dependency Injection

  31. UI Architecture Patterns

  32. Also doesn’t really help

  33. Bias Towards Interfaces

  34. Injecting Interfaces

  35. Different Interface Injection

  36. Explicit Dependencies

  37. Perfect Tool For The Job

  38. Perfect Tool For The Job

  39. Recap 2 • Use SRP on injection code • Not

    relevant for UI architecture • Flexible for providing interfaces • Perfect for explicit dependencies
  40. Testing Time!

  41. Unit Testing

  42. Don’t use it for unit testing

  43. Remember This?

  44. Remember This?

  45. No Need For DI

  46. Integration Testing

  47. Fakes?

  48. Module For Fake

  49. Test Component

  50. Test Application

  51. Custom Test Runner

  52. Supply Test Application

  53. Using Custom Test Runner

  54. Example Integration Test

  55. Small issue

  56. Unused Test Runner

  57. What About Robolectric?

  58. Custom Robolectric Application

  59. Conclusion

  60. Who is this guy? Brian Gardner @bgardner7 Big Nerd Ranch

    We Teach, We Develop, We Write