Coder Social home page Coder Social logo

alexlindroos / android-architecture-and-testing-sample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codemateltd/android-architecture-and-testing-sample

0.0 2.0 0.0 163 KB

Android MVP & Clean Architecture sample with unit and instrumentation tests

Java 100.00%

android-architecture-and-testing-sample's Introduction

Android MVP & Clean Architecture sample with Unit and Instrumentation tests

BlogReader App

This sample app loads and displays blog posts in a list. By clicking a blog post, you are taken to a detail UI, which shows the entire blog post body and comments.

The app uses a fake blogpost API to load the posts and comments. All data is cached locally, so no unneeded network requests are being made until the cache becomes invalid.

Maintainability

The application has almost 90% test coverage, so adding / changing features is not scary at all. You can always run the tests after making changes, and if they pass, you can be pretty sure you didn't break anything vital.

Ain't nobody got time for tests

Actually, there's only about 10 test functions, and the longest one only has 8 lines of code. That's not so much, is it?

MVP? Clean? SOLID?

By following Model-View-Presenter, Clean Architecture and SOLID Principles, this app becomes:

  • Easy to test. Business rules can be easily tested without Android emulators / devices in milliseconds. And the UI tests are't that horrible to write either.
  • Easy to maintain. Adding / modifying functionality is easy, and doesn't cause a regression bug hell as everything is separated and tested.
  • Independent of external third-party libraries. Cache can easily be replaced with Realm, without modifying the main application logic. The application simply doesn't care about what frameworks we're using.
  • Independent of UI. The UI can easily be changed without changing the existing business logic. This could be easily converted to a desktop or even a command line app.

Everything is nicely decoupled. The application isn't dependent on concrete implementation details. They are more like plugins, and they actually depend on the application; not the other way around.

How to run

The project has two build variants:

mock
Instead of loading real data, populates the blog list and comments from a static FakeBlogApi to make testing easy. Also contains all the tests.
prod
The "real" app that actually loads real blog and comment data from a real API. Does not contain tests, they are in the mock variant.

Package structure

com.codemate.blogreader.data

Blog API and Cache implementations. The Blog API is defined in a simple interface that has getPosts() and getComments(int postId) methods. The implementation is then automatically generated by the Retrofit library.

com.codemate.blogreader.domain

Contains the business rules (usecases) that are our applications main functionality. No Android or external dependencies here, just plain Java.

Also contains the BlogPost and Comment models and the PostCache and CommentCache interfaces that the data layer implements for SharedPrefCache.

com.codemate.blogreader.presentation

All the Android-related UI stuff, such as Activities and RecyclerAdapters. Also just plain Java Presenter objects and View interfaces implemented by the Activities.

android-architecture-and-testing-sample's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.