Skip to main content

Getting Started with Test Driven Development Concept and Guidelines

Recently I have been encouraged to start working using Test driven development , so I took like a quick run over the Concepts and Guidelines and
Decided to post my achievement Notes and result of each phase I study ,implement and give some points to those who are interested in getting started
just like me so lets start

First

The Main concept or shall I say the main though that should be in your mind while Doing TDD is simply this “Every new feature begins with a test” what does this mean ?

It means simply you don’t write any code you begin with you tests, maybe your test cases not just one many as many as you think of start throwing those
tests before even writing interfaces to test them that’s it the first and most important yet the basic foundation of Test Driven Development is to
“Write tests first ” simple enough.

Second

These Tests will fail “Cause there is not code to test so they should fail else then there is something wrong with your tests” Mostly these tests are
driven from use cases, test cases or user stories

Note : What is the defference why should I write tests first “heck that takes even more time to do the whole thing ”

Answer : why ? because you write your tests before your code is written so you re-factor and accommodate your code to use unit tests while you first
write it, Also it helps you focus on the Business side of your application makes you focus on the Requirements at most and everything else comes second


Here is an excellent example of code that is really simple and illustrates TDD with code if you are tired of me running my mouth http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx


Unit Testing Framework there are so many frameworks in Unit testing, for me I prefer NUnit and for Mocking I use MOQ framework

Test Driven Development Cycle

Ok after I did some reading hashing and slashing I was able to define the TDD “Test Driven Development” Cycle and it came like this

1. Write a test or more

2. Run the test. It fails to compile because the code you're trying to test doesn't even exist yet! (This is the same thing as failing.) so if it
throw exception cause there is not method or a class called blab la bla then that counts as a failed test

3. Write a bare-bones stub to make the test compile in other words make the test class build by creating the necessary classes and methods

4. Run the test. It should fail since you did not logic so far so it would make since that the logic you are trying to test is not working and it
should fail. (If it doesn't, then the test wasn't very good.)

5. Implement the code to make the test pass, In this step you work on passing the test in other words write the necessary code to make this test
pass

6. Run the test. It should pass “now that your logic is done and you are probably using the logic write”. (If it doesn't, back up one step and
try again.)

7. Last Start over with a new test! And go all over one time

Coding By intention

A very useful concept use for TDD is called Coding by intention it is simply the process of writing code while thinking “i am going to need”
and not I need to . another explanation is to write the test without consideration of what should and what should not be implanted wither it is a class
or a method, and thinking I’m going to need helps you do that

The Result was

well tested code easy to read and debug and yes it is very reusable in so many ways

Another yet very important primary concept of the TDD

"Dont write any code untill you have a test that fails"

The most important steps of the Test driven development cycle is

Write as simple and small code to make the application only compile next step write enough code to make the test pass

Comments

Popular posts from this blog

Xamarin Forms Core components Part 1 Dependency Service

Intro Xamarin Forms is a collection of controls that can be used and rendered on multiple platforms, and in order of them to function as they are suppose to, they do need a set of core components that defines the way these controls, in how they are created, how they are rendered to how they are used, of course every platform is different and sometimes a platform specific extra configuration is required, specially that there are so many differences between the different platforms in matter of design, user experience and operating system behavior. So one of the core components of  Xamarin  Forms is the Dependency Service, and by the name suggest it does act as the dependency resolver for all forms controls, if you are not familiar with IOC " I nversion O f C ontrol" and Dependency Injection please refer to the link for a quick intro i wrote a while ago on IOC  IOC Part 1 - Inversion of control Principle .  And as of such the Dependency Service is the concrete inboxe

Xamarin Forms: XAML Creating Custom Controls The MVVM Way

Intro For a growing UI page there always comes a need to create sub views that can be used inside a bigger view, and for that we need custom controls, which are controls that are derived either from a layout or a simple view which is the basic control for almost any UI component in Xamarin forms, and therefore for a start i will use that as an example. And in such example we will create a custom control with a set of bindable properties and explain how they work, also how to add an event that can also be bound to Commands Lets Create the control  I have just went ahead and created a custom control that inherits from Xamarin.Forms.View and have some properties such color and checked all properties to be bound to by the ViewModel serving as the datacontext of the this control. here is the code below using System; using Xamarin.Forms; namespace UserControls { public class CustomView : View { public Color Color { get ; set ;

Windows Phone 8 - Application bar command binding MVVM

This is a short post in which i will explain how on Windows phone 8 to bind the application bar button or menu item, first this is only a fix for the  BindableApplicationbar  which supports windows phone 7 only, i just made it support windows 8 no features added or anything. i have uploaded the dll file here so it can be accessible easily here is the link to download http://sdrv.ms/RApUal now that you got the link lets check how we gonna use it you can refer to BinableApplicationbar  or check out the code here that i actually used in my app and i already read it there !  Add a reference to the BindableApplicationBar library here is the link again  http://sdrv.ms/RApUal Add XML namespace declaration in your page's XAML: xmlns : bar ="clr-namespace:BindableApplicationBar;assembly=BindableApplicationBar" Set Bindable.ApplicationBar property on your page code as in the snippet below: < phone : PhoneApplicationPage >     …     < bar : Bindable.App