One of the best things about MvvmCross (and Mvvm) is its
testability.
With the MvvmCross architecture I can test most of my code
without the need for a phone (I’m assuming phone development is your focus!).
One of the common excuses for not doing unit testing is 'I haven’t
got time' - I’ve been guilty of this too, the problem for me is lack of decent
tooling for creating unit tests.
It’s too time consuming - creating unit test projects, unit
test files, sorting out the mocking of the interfaces blah, blah.
I’m not going to get into a debate about unit testing -
there is better info out on the interweb that can explain the pros and cons of
doing it.
I will say one thing though when you are doing multi-platform development that require hard to
use equipment like phones I think you will find with a bit of effort and
discipline doing unit testing will help enormously and speed your development
time not slow it down.
You probably saying 'That’s great Adrian thanks for the
lecture - but I know all that, so what’s this go to do with the Ninja?'
I’m glad you asked :-)
I want to take some of the time consuming steps out of doing
unit testing so here is what I have in the pipeline for Ninja Coder for
MvvmCross v1.2.0 coming out very soon (next couple of days hopefully!).
1) I
switched the Testing project template from MsTest to NUnit (there is hardly any
difference between the two but I agreed to switch)
2)
Provided the test project template with Mocking support using Moq.
3) Created
a BaseClass which all unit test classes derive from - this means some of the
laborious tasks are done in the base class and don’t need to be done again.
4)
Created a Mock Dispatcher (required for the unit testing to handle
ShowViewModel requests amongst other things).
5) When
you create a new MvvmCross Solution it will create a test project for the tests
(this isn’t actually new but just wanted to re-iterate the point).
6) When
you create a new ViewModel and Views from the Ninja it will create a TestViewModel
file in the test project by default.
7) When
you add plugins to your MvvmCross solution it will do a couple of things.
a)
The viewmodels will now have their constructors amended automatically to inject
the interfaces required to use the plugins.
b)
**Relevant (stub) tests will be added to the TestViewModel file in step 6 - all
interfaces will be mocked up ready to go.
**
Work in progress on this one I can see more being done in this area.
8) The soon to come Add Service functionality will follow the same pattern as the testing support for Add plugin.
8) The soon to come Add Service functionality will follow the same pattern as the testing support for Add plugin.
The above isn’t going to make unit testing a zero effort
activity but should make things a LOT easier.
As always if people can see ways of improving this then get in
touch!
Really nice job!
ReplyDeleteSo much useful!
Waiting now for the Add service functionality :)
But don't forget to take some hollydays...