GithubHelp home page GithubHelp logo

benz93chung / grpcmvvm Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 132 KB

An explorative Android project of gRPC + MVVM + LiveData

Kotlin 100.00%
android grpc protobuf protocol-buffers livedata livedata-viewmodel mvvm mvvm-android reactive kotlin

grpcmvvm's Introduction

GrpcMvvm

Reactive gRPC Android App

An explorative Android project of gRPC + MVVM + LiveData

Alt Text

Setup and usage

  • Clone this project
  • Open project with Android Studio and build it
    • Based on helloworld.proto...
    • ...protoc will generate gRPC code to Android project in build folder
  • Follow this guide to set up and run server (please take note of IP and port it is running on)
    https://grpc.io/docs/quickstart/java/
  • Once server is running with said IP and port, change accordingly at Injector.kt
    // Provide GrpcService
    private fun provideGrpcService() = GrpcService(
        "192.168.1.107", // <- insert your IP here
        50051 // <- insert your port here
    )
  • Build project, and run at emulator

Bonus

Unit test included!

Find out more at .../app/src/test
@Test
fun sayHello_Mars_ReturnsHelloMars() {
    // Given that I want to say hello to Mars
    val nameToGreetTo = "Mars"
    val expectedGreeting = "Hello Mars"

    greeterViewModel.sayHello(nameToGreetTo)

    val actualGreeting = greeterViewModel.greeting.getTestValue()

    // Then the getThatGreeting is Hello Mars
    assertThat(actualGreeting).matches(expectedGreeting)
}

Additional notes on unit test strategy

For the written unit test, it is written as such to explore on how gRPC stuff (protoc generated code) can be mocked and tested along with Android stuff (ViewModel).

If you have seen it, a channel is set up based on a fake server implementation and gets injected to the creation of the ViewModel like as if the said channel provides a passage to the "server".

You would not need to write such a test down to that level of mocking gRPC stuff or so, but just write tests to test against just the Android stuff instead (in this case, you would mock what the repository returns to the ViewModel), especially if your backend team already wrote unit tests that tests on client interaction of gRPC code.

Credits

This project is inspired by prongbang's Android + gRPC repository
https://github.com/prongbang/android-grpc

If you are going to star this repository, please also leave a star to prongbang's. :)

grpcmvvm's People

Contributors

benz93chung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

binhcse

grpcmvvm's Issues

No issues just an appreciation post

I've used your template in my project/startup and it's been a life saver trying to understand all the underlying concepts. Thank you so much.

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.