commons-app / apps-android-commons

The Wikimedia Commons Android app allows users to upload pictures from their Android phone/tablet to Wikimedia Commons
https://commons-app.github.io/
Apache License 2.0
1.02k stars 1.23k forks source link

Switching to test driven programming #1883

Open neslihanturan opened 6 years ago

neslihanturan commented 6 years ago

Summary:

Hi team, since our time spent for bug fixes seems a little high, maybe switching to test driven programming can be a solution. Since on our WMCZ grant session, we will have several quality improvement, then our code base may be ready for test driven programming. What do you think?

misaochan commented 6 years ago

I am assuming you meant "test-driven programming", so I took the liberty of editing your post. ;)

I agree, I think this would be well worth the investment. Would love comments from experienced devs especially - @nicolas-raoul @whym @dbrant @psh ?

nicolas-raoul commented 6 years ago

I don't think test-driven programming is a great fit for most parts of our project because:

That being said, there are parts of the project that could certainly benefit from test-driven programming, so I suggest starting with those. For instance the non-GUI part of EXIF parsing and EXIF modification, this could be a good start.

neslihanturan commented 6 years ago

If we can well define where we want to have it, we can include this as a rule to contributors documents. So that new comers also can now, they need to write tests if possible.

And since we can't write tests for GUI, maybe we can make sure we separated GUI layer as much as we can.

whym commented 6 years ago

In general, I think it's a good exercise to ask yourself 'can I write tests?' when creating and modifying a feature, and perhaps more importantly, when fixing a bug so that the same bug will not happen again easily.

We have utility classes and methods (e.g. app/src/main/java/fr/free/nrw/commons/Utils.java) for which we can naturally write tests. Perhaps we can start from those.

GUI features are harder to test, but not impossible in my opinion. I believe something like app/src/androidTest/java/fr/free/nrw/commons/SettingsActivityTest.java is a good way to catch bugs that might sneak in unintentionally. High coverage would probably be unrealistic, but a few GUI tests will be great to have to prevent breaking things.

ilgazer commented 6 years ago

In my opinion, having more tests could be beneficial. On the other hand, making tests a requirement could dissuade less experienced developers(that's me) from developing new features. For example, even though I built upon psh's MVP architecture for #1796, I would have shied away from working on that if I had to write tests for my code, something I have no experience or knowledge about. The same holds for my EXIF modification code. In conclusion, I think that while encouraging tests is a good idea, mandatory tests would do more harm than good.

albendz commented 6 years ago

I'm new to reviewing code for this project and I'm still trying to understand the quality bar for reviews. This recent example shows something I'm confused about: https://github.com/commons-app/apps-android-commons/pull/1888

Test driven development can be heavy handed, especially when new programmers in a formal program or learning on their own do not learn testing typically. However, it looks like we could make some small changes to the contributing guidelines to explicitly say that everything needs to be unit tested and if you can't do so easily, provide a reason in the PR and we will waive the need to unit test if it's UI or 2FA as Nicholas points out.

@ilgazer I agree that mandatory tests will be frustrating and potentially discourage new contributors. Would you think if we say "tests or a justification of why there are no tests is mandatory" would be better? Then the more experienced project test contributors can provide pointers.

ashishkumar468 commented 6 years ago

Although TDD enables refactoring in an anxiety-free, predictable way, and of-course enforces standards, reaching slowly towards bug free and more stabler product, not all of the developers(actually most of them) follow it and actually know it. Even though it has a lot of advantages, we all know that it would require extra efforts to those who are not acquainted with it. Having it would be great, but might discourage early stage contributors. And if we talk about improvements in code standards improvement, of-course TDD would have been the best solution, but for the time period, until the app reaches stable in terms of development and adding new features (which i am not sure it is now), where we have enough of resources and time and not loaded with new features, IMO, and I may be wrong, we can go ahead with the current policy of not mandating it (but of-course encouraging it to those who can and are willing to go for it). Also code standards can and is being currently enforced by the code reviewers (thanks to the concept of PR's). But not accepting PR's because of test cases, in my opinion, would not be the best thing to do as of now. However I would recommend to introduce a code architecture pattern, say MVP or MVVM (Please correct me if we already follow any of these). That will automatically raise code standards and improve code quality.

misaochan commented 6 years ago

Thanks for the input everyone!

Based on the opinions here, my proposed solution:

What do you guys think?

ilgazer commented 6 years ago

@misaochan Your compromise of only requiring grantees to write unit tests is a really good idea. If we will apply as a GSoC project, maybe we could have the same requirement for them.

misaochan commented 6 years ago

@ilgazer Good idea! 👍

ilgazer commented 6 years ago

Also, I think linking to some good resources in the wiki about where to learn testing would help a lot. I distinctly remember being overwhelmed by the abundance of stuff to learn and giving up when I tried to start writing tests for #1712. I still have no clue about how to write tests.

NotSoImportant commented 3 years ago

Is this a stale issue?

neslihanturan commented 3 years ago

I don't think this is gonna happen soon. If you have suggestions/things to say about this issue feel free to share.

NotSoImportant commented 3 years ago

I was just wondering as something was put to done if now you have applied it or what are the next steps.

misaochan commented 3 years ago

I would consider this a semi-success. All PRs for new features/enhancements now require unit tests, as mentioned in our contribution guidelines, and our code coverage has also increased substantially. However, I don't think most contributors are applying true TDD principles (which is different from just writing tests for their code).