• Save
Introduction to TDD with FlexUnit
Upcoming SlideShare
Loading in...5
×
 

Introduction to TDD with FlexUnit

on

  • 2,883 views

Introducing TDD with FlexUnit and FlashBuilder :)

Introducing TDD with FlexUnit and FlashBuilder :)

Statistics

Views

Total Views
2,883
Views on SlideShare
2,883
Embed Views
0

Actions

Likes
3
Downloads
1
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Introduction to TDD with FlexUnit Introduction to TDD with FlexUnit Presentation Transcript

  • Intro toTDD with FlexUnit [ Anupom Syam ]
  • TDD Cycle
  • Why?TDD is like Source Control you don’t know howmuch you need it until you start using it.
  • Benefits?• Test first approach is Aspect Driven• Enforces the developer to be the first consumer of their own program• Makes it easy to Refactor• Simplifies Integration Testing• Unit tests are living documentation of the system• Encourages modular design• Gives greater level of confidence in the code• Reduces debugging time
  • Terminology Assertion Test Casetrue false statements that are used to verify the a set of conditions to determine the correctness of some behavior of the unit functionalities of program Test Suite Fixture a set of tests that all share the same fixture all the things that must be in place in order to run a testCode Coverage Fakes & Mocks Dummy objects that simulates the behavior of complex,percentage of a program tested by by a test suite real objects
  • Phases of a Test Set Up Exercise setting up the test interact with the system under fixture testBlank State Tear Down Verify determine whether the tear down the test fixture to expected outcome has been return to the original state obtained
  • What?• A unit testing framework for Flex and ActionScript.• Similar to JUnit - the original Java unit testing framework.• Comes with a graphical test runner.• Can test both Flex and AS3 projects
  • Let’s try a “HelloWorld” unit test using FlexUnit
  • 1. Create a new project
  • 1. Create a new project
  • 2. Create a new method package { import flash.display.Sprite; public class Calculator extends Sprite { public function Calculator() { } public function add(x:int, y:int):int { return 0; } } }
  • 3. Create a test case class
  • 3. Create a test case class
  • 3. Create a test case class
  • package flexUnitTests { import flexunit.framework.Assert; 3. Create a public class CalculatorTest { test case class [Before] public function setUp():void { } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.fail("Test method Not yet implemented"); } } }
  • package flexUnitTests { import flexunit.framework.Assert; public class CalculatorTest { 4. Create a private var calculator:Calculator;failing test case [Before] public function setUp():void { calculator = new Calculator(); } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.assertEquals(calculator.add(2, 3), 5); } }
  • 5. Execute the test
  • 5. Execute the test
  • 5. Execute the test
  • 6. Write the body of the method package { import flash.display.Sprite; public class Calculator extends Sprite { public function Calculator() { } public function add(x:int, y:int):int { return x+y; } } }
  • 7. Execute the test again
  • 7. Execute the test again
  • 7. Execute the test again
  • Good Job!
  • package flexUnitTests { import flexunit.framework.Assert; public class CalculatorTest { Components of private var calculator:Calculator;a Test Case Class [Before] public function setUp():void { calculator = new Calculator(); } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.assertEquals(calculator.add(2, 3), 5); } }
  • package flexUnitTests { import flexunit.framework.Assert; public class CalculatorTest { Components of private var calculator:Calculator;a Test Case Class [Before] public function setUp():void { calculator = new Calculator(); } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.assertEquals(calculator.add(2, 3), 5); } }
  • package flexUnitTests { import flexunit.framework.Assert; public class CalculatorTest { Components of private var calculator:Calculator;a Test Case Class [Before] public function setUp():void { calculator = new Calculator(); } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.assertEquals(calculator.add(2, 3), 5); } }
  • package flexUnitTests { import flexunit.framework.Assert; public class CalculatorTest { Components of private var calculator:Calculator;a Test Case Class [Before] public function setUp():void { calculator = new Calculator(); } [After] public function tearDown():void { } [BeforeClass] public static function setUpBeforeClass():void { } [AfterClass] public static function tearDownAfterClass():void { } [Test] public function testAdd():void { Assert.assertEquals(calculator.add(2, 3), 5); } }
  • Test Suite Class package flexUnitTests { import flexUnitTests.CalculatorTest; [Suite] [RunWith("org.flexunit.runners.Suite")] public class CalculatorTestSuite { public var test1:flexUnitTests.CalculatorTest; } }
  • Myths• TDD is a Golden Hammer• We will not need Testers any more• TDD eradicates bugs from the code• TDD ensures that the code is up to the requirement
  • Facts• Don’t expect TDD to solve all of your problems.• TDD reduces the amount of QA but we will still need Testers :)• TDD may reduce number of bugs• Tests might share the same blind spots as your code because of misunderstanding of requirements.
  • Useful Links• FlexUnit http://www.flexunit.org/• FlexUnit 4.0 http://docs.flexunit.org/index.php?title=Main_Page• A brief and beautiful overview of FlexUnit http://www.digitalprimates.net/author/codeslinger/2009/05/03/ flexunit-4-in-360-seconds/• A very good read http://www.amazon.com/Working-Effectively-Legacy-Michael- Feathers/dp/0131177052
  • Thank you!