Tuesday, 25 March 2014

Test First Development - Part 1

 

Test first development, also known as Test Driven Development (TDD) is a development style in which you write the unit tests before you write the code to test.   The advantage of test driven development is, that you force yourself to think about how the unit (the component) is going to work. In other words, you force yourself to think about the contract of its interface. Actually, the asserts in the unit test specify the contract of the unit.  

Sometimes, when writing a unit test after you have implemented some component, you realize that it is hard to test. You may then decide to make some design changes to the code, to make it easier to test. During test driven development (TDD) you force yourself to think about both the contract (as mentioned above), and the testability of the component, before you start implementing it. This way you may naturally design components that are easier to test, rather than having to redesign them later.

Test-driven development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes an (initially failing) automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, and finally refactors the new code to acceptable standards. Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999, but more recently has created more general interest in its own right.

 

 

Introduction to Test-First Development

 

image

 

 

image

 

 

 

 

Demo: Ye Old Way Developer's Tested

 

image

 

 

image

 

 

image

 

 

Note:  Here developer has to create test cases for scenario passing and without passing the Bark parameters of Dog class.

 

 

image

 

 

image

 

 

 

image

 

 

 

 

Unit Testing Frameworks

image

 

 

 

image

 

 

image

 

 

 

image

 

 

 

Demo of Unit Tests in VS

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

Demo of Test-First development

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

Instead we have to write test cases to ensure the functionality of business suggests

image

 

 

 

 

Writing Unit Tests Part I

 

image

 

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

The First Failing Test

image

 

 

image

 

 

image

 

 

image

 

 

 

Making The First Test Pass

image

 

 

image

 

 

 

image

 

 

 

The Second Test

image

 

 

image

 

 

image

 

 

image

 

 

 

Refactoring a Third Test

image

 

 

 

image

 

 

image

 

 

image

 

 

 

 

Writing Unit Tests II

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

Note:  “Object 1” is referring Method A which calls another object “object 3” but still this Unit test

 

 

image

 

Note:  “Object 1” is referring Method A which calls another Data base, so it become Integration Test. We can very write Integration Test with Unit Test framework.

 

 

image

 

 

image

 

 

 

Final Project Organization

image

 

 

 

NUnit Artifacts

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

 

Introduction to Refactoring

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Creation of Interface

 

image

 

 

image

 

 

image

 

 

 

Creation of BaseClass

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

Driving Design with Unit Tests

image

 

 

 

image

 

 

image

 

 

Note:  If you change the existing QC passed code, Test Driven Development process will cover up your existing code by indicating RED signal.

 

 

 

image

 

 

image

 

 

 

image

 

 

Problem with HTTP Context

image

 

 

image

 

 

 

Decoupling the HttpContext Dependency

 

image

 

 

image

 

 

image

 

 

image

 

image

 

 

image

 

 

 

Other Design Benefits

image

 

 

 

image

 

 

image

 

 

image

 

 

 

 

Isolating Code

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

image

 

 

 

 

Introducing the Application

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Demo: First Test Double

 

image

 

 

 

Demo: The Need for a Stub

 

image

 

 

image

 

 

image

 

 

 

Demo: Stub and Spy

 

image

 

 

image

 

 

image

 

 

 

Demo: Using a Mock

 

image

 

 

image

 

 

image

 

 

image

 

 

Now Let us use the Real Mocking framework to test DB related artefacts

 

Repository Mocking

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

View Mocking

 

image

 

 

image

 

 

image

 

 

Summary

 

image

 

 

 

Acceptance Test Driven Development

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

Gherkin Tool for ATD

image

 

 

image

 

 

image

 

 

 

SpecFlow tool for ATD

 

SpecFlow is based on Gherkin and easy to use.

 

image

 

 

 

Introduction to Specflow

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Implementing Scenario Steps

 

image

 

 

image

 

 

image

 

 

image

 

 

 

Behavior Driven Development

 

image

 

 

image

 

 

image

 

 

image

 

 

image

 

 

 

image

 

 

image

 

 

image

 

image

 

 

image

 

 

Summary

Reducing Class Coupling via below architecture for Good TDD

 

image

 

 

 

Blogger Labels: Test,Development,Part,Driven,unit,advantage,component,interface,Sometimes,components,repetition,developer,improvement,concepts,Introduction,Demo,Note,Here,scenario,Bark,parameters,Frameworks,Tests,Instead,Pass,Second,Third,Object,Method,Data,Integration,framework,Final,Project,Organization,NUnit,Artifacts,Creation,BaseClass,Design,Problem,Context,HttpContext,Dependency,Benefits,Code,Application,Double,Stub,Mock,Real,artefacts,Repository,View,Summary,Acceptance,Gherkin,Tool,Steps,Behavior,Class,architecture

No comments:

Post a Comment