Tuesday, September 13, 2011

phpunit Mock Objects

Since PHP is widely used as web application language , TDD ( Test Driven Development) is really important factor for web application development. All other popular languages which used *unit for testing classes and packages.

I'm really thanks to Sebastian Bergmann who introduce phpunit for PHP web application testing.


Web Application structured with mulity layers like DAO , Service , Controllers and views . So its really helpful test layer by layer. If its DAO layer then test mainly involve with data base operations. but if It's in above layers then It's really need to mock below layers and tests. Then phpunit mock objects play a major role to decouple layers and tests .

Following example shows how to write test for each layer
Test DAO Layer
$countryDao 	= 	new CountryDAO();
$result		=	$countryDao->searchCountryByCode('UK');
$this->assertType('Country',$result);
$this->assertEquals('UK',$result->getCountryCode());
$this->assertEquals('United Kingdom',$result->getCountryName));
Test Service Layer 
$country = new Country();
$country->setCountryCode('UK');
$country->setCountryName('United Kingdom');
$countryDao	=	$this->getMock('CountryDAO'); 
			$this->redhatCountry->expects($this->any())
                       ->method('searchCountryByCode')
                       ->will($this->returnValue($country));
$result		=	$countryDao->searchCountryByCode('UK');
$this->assertType('Country',$result);
$this->assertEquals('UK',$result->getCountryCode());
$this->assertEquals('United Kingdom',$result->getCountryName));

Thursday, September 8, 2011

How to use Mind-map to Develop story

I have experienced using mind-maps for developing small sets of features. At the beginning it's necessary to identify all the tasks need to be taken place to complete the story. In the Mind-map , we can keep task of  break downs as well as development documents according to their priority..


FreeMind Tool is used to create above Mind-Map

Wednesday, September 7, 2011

Use Case diagram for captureing "Customer Voice"

Initial stage of software project, Business modeling and Requirement analysis play a major role. Use Case diagram mainly used for capture the requirements. Use case diagram building blocks are

Actor
A role that interacts with the system.
Represents a role, not individuals; can be a person or a device or another system.
Communicate with the system by sending and/or receiving messages.
An actor may participate in many use cases; a use case may have several actors participating in it. 


Use Case
  • Is an abstraction of a set of sequences that yield some functionality.
  • Represents some user-visible function.
  • Is always initiated by an "actor" 
  • Describes the interaction between the actors and the system for a system function.
  • Achieves a discrete goal for the actor.
Use Case Diagram
A graphical representation of the Use Cases of a system, its actors, and the interaction between them.