Some background first: we're developing custom mobile apps, most of them tailor made for B2E scenarios. At the moment, we're only testing manually. I know some people consider this a cardinal sin, but thanks to the maturity level of our developers, we manage.
We'd like to introduce automated testing into our projects (new projects, but ideally also in apps which are already 'live' but where we provide support for). I have a good grasp of what (and how) to test in a UI/End-to-End test, but that seems to be only the tip of the testing
I know technically how unit tests are supposed to work, and the Internet is full of tutorials which explain how to unit test mobile apps. That means: which frameworks/tools you can use depending on the platforms you build for and the IDE you're working with. We use Xamarin, but this question applies to other technologies as well.
My problem is: what can I unit test in a mobile app? Roughly speaking, our apps follow the Model-View-Controller design pattern and consist of the following parts:
- ORM/Database layer. We use a custom ORM framework built on SQLite.NET which itself is tried and tested. I'm not sure how to write unit tests here.
- Business logic. This is actually a part which can be covered by unit tests, and most tutorials on how to unit test mobile apps show a testing example from this domain. However, when I have to write 20 lines of code to produce six orthogonal tests for a simple method which determines the type of a barcode (e.g. if it's an EAN code, a Track&Trace code, a loyalty card number, etc.) which consists of 5 lines of code itself, I get the feeling I'm a bit overzealous.
- Calling external services and processing results. We usually work with WebServices and
wsdl.exegenerates proxy code for us. Because this depends on an external system, it's hard to unit test but I can probably 'fake' a response. Still, it looks like a lot of work for something where (in our experience) the problem almost always lies in wrong data.
- View controllers / Activities / Fragments (depending on the OS). We're careful to avoid the Massive View Controller anti-pattern; still, these are often the largest parts of our application (well, at least the most work to write). I have the feeling that this is the domain where we can gain the most, but I have no idea how to do it.
- Storyboards / Layout XMLs (again depending on the OS). I'm not sure if this can be unit-tested at all, or that they should be together with their controllers.
I've found some unit tests for ASP.NET MVC but I struggle on how to convert them to meaningful unit tests for mobile apps.
Examples which work only for, say, Android apps built in Java, are welcome; even though they don't match the technologies we use, they can be useful to future readers and I can probably convert them to something we actually can use in our projects.