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
christophsturm
01/05/2021, 9:06 AM
If you do TDD, yes. But in the end I would only write a test for it if it makes you feel safer.
christophsturm
01/05/2021, 9:07 AM
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
Simon Lin
01/05/2021, 9:45 AM
only write a test for it if it makes you feel safer
It is a nice opinion.
d
Daniel
01/05/2021, 4:49 PM
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)