170 likes | 295 Views
Unit Testing Flex with FlexUnit 4 and Flash Builder 4. Chris Luebcke. Unit Testing - Why?. Gets The Bad News Early. Improves Technical Design. Defines Behavior. Documents Code. Enables Safe Refactoring. Defends Against Regression Bugs. Discovers Bugs In Initial Implementation.
E N D
Unit Testing Flexwith FlexUnit 4and Flash Builder 4 • Chris Luebcke
Unit Testing - Why? Gets The Bad News Early Improves Technical Design Defines Behavior Documents Code Enables Safe Refactoring Defends Against Regression Bugs Discovers Bugs In Initial Implementation
A Brief History FlexUnit 4 ASUnit flUnit SUnit cfcUnit utPLSQL CUnit JSUnit RUnit EUnit PGUnit xUnit Visual Assert mlUnit GUnit FlexUnit 0.9 xUnit.Net HUnit SimplyVBUnit NUnit FSTest curlUnit RCUnit ShUnit Test::Class Roaster PyUnit googletest csUnit Test::Unit PHPUnit .TEST FRUIT CppUnit FPCUnit jsUnit utMySQL
xUnit Testing Patterns System Under Test (SUT) (a.k.a. your class) CI Test Suite Test Case Fixtures Assertion Test Runner methodOne() Assertion methodTwo() Assertion Fixtures Assertion methodThree() Test Case System Under Test (SUT) (a.k.a. your other class) Assertion Fixtures Assertion Assertion methodOne() Assertion methodTwo() Fixtures methodThree()
Development Practices Old Skool Nu Skool TDD Skool Code Code Test Code Test Code FAIL Code Code Test Test Test Code WIN WIN
A Generated Test Class Doesn’t Extend TestClass What I got for specifying “Class to Test” in the wizard. (not all that helpful actually) A commented-out bootstrap (pretty handy, at least at first)
Let’s Make It Assert Something 1. Uncomment the test method 2. Watch it fail because you havent’t imported Assert 3. Import flexunit.flexframework.Assert Fail Use this guy Not this guy
Let’s Run Our Test (finally) Project context menu Run As > FlexUnit Tests Ok!
The Test Runner Nothing to see here, move along.
The Test Results Fail... but why? Hmm? Oh, that’s right
Interlude: Be Assertive General Form Assert.assertSomething([failure message,] parameters) Specifically... Assert.assertTrue(value) Assert.assertFalse(value) Assert.assertEquals(expected value, value) Assert.assertStrictlyEquals(expected value, value) Assert.assertNull(value) Assert.assertNotNull(value) Assert.fail()
A More Useful Test A system... ...under test
Now For Better Coverage Ah, that’s better Eww, let’s fix that
Interlude: That’s Meta(Data) [Test] [Ignore] [Before] [BeforeClass] [Test] [Suite] [After] [AfterClass] [Test(expects=”error class”)] [Test(async,timeout=”250”)]
Exercises Left To The Reader Writing asynchronous tests Continuous Integration Ordering test execution Theories Hamcrest RunWith Adapters What To Test
FIN big ups to Mike Labriola @ Digital Primates, Matt Chotin @ Adobe and everyone else involved in bringing the awesomeness of FU4+FB4 to life http://flexunit.org cluebcke@yahoo.com