I am a firm believer of writing unit test before you check in any code. Writing unit test and making sure that your code works as expected gives a lot more confidence in your code.
One of the libraries that I use which makes my unit testing code easier to write is Mocking Framework like Moq. Moq is a cool library I love to use. The api that MOQ has are so easy to find out and understand what they actually do. I would recommend this framework to anyone who is starting doing Unit Tests.
Some of the important things while writing code that you have to always keep in mind are:
1) Open-Closed principle.. i.e open for extension closed for modification.
2) Single Point of responsibility.
3) Program to an interface and not to concrete classes.
4) Prefer composition over inheritance. etc
In this sample example I want to test the LibraryService Class which takes in 1 dependency - IDataService. The dependency is passed in through constructor injection. This is one was to inject the dependency, and the code is not tightly couple to a particular instance of the DataService. You can implement IDataService which gets the books from the DataBase or XmlFile or any other datasource.
Welcoming the Xamarin team to Microsoft
2 months ago