Is it worth to write the test for the simplest cas...
# test
s
Is it worth to write the test for the simplest case in product project? for example:
Copy code
// In android ViewModel

val user = MutableLiveData<User>()

fun loadUser() {
    viewModelScope.launch {
         user.value = userRepository.getUser()
   }
}
Do I need to write a test for
loadUser
? or it only show in a tutorial?
c
If you do TDD, yes. But in the end I would only write a test for it if it makes you feel safer.
I even write a test to create a new class or to stub out all the api that I need. But if you don’t feel that it adds value for you don’t do it
🙇‍♂️ 1
s
only write a test for it if it makes you feel safer
It is a nice opinion.
d
Things tend to get more complicated, so pinning requirements early is a good habit. Also when there is already a test class its more likely your coworker also adds tests. It's easier to decide to write no tests when there are none to begin with. I would also recommend a ui test here.. only then you know if the threading is done right. Unit tests can very well be green and the app still crashes (wrong dispatcher is enough)
🙇‍♂️ 1