Wednesday, February 10. 2010A Parameterized Testrunner for FlexUnitA couple of days ago, I complained about FlexUnit's Theories. Well, with a bit of encouragement from @drewbourne, I broke down and wrote a proper parameterized testrunner:
And that code will do exactly what you'd expect: run three test cases, one for each of the inputs. If one test fails, the others will still run. Helpful error messages will be provided when a test fails. The source can be downloaded from: http://gist.github.com/299871 (and it will be getting a new home when ever I get around to releasing all of my AS utilities) Look useful? Give it a try and tell me what you think – I'd love to know. Friday, February 5. 2010FlexUnit's Test Theories: Don't BotherI've just been playing around with FlexUnit 4's nifty new "Test Theories"… And I have come to the conclusion that, right now, they are basically worthless. Here's why:
So, don't waste your time on Theories just yet. For now, just use a
Or, if you want to test the cartesian product of a set of data, use my handy cartesian product function:
Followup: as Alan (see comments) said, what I really want is a parameterized testrunner. So I've gone ahead and written one. See my post on a Parameterized Testrunner for FlexUnit. Monday, December 7. 2009Best Ever Implementation of "indexOf"!(alternate title: The "Fail Early, Fail Often" Principle in Action) I would like to award Adobe the "best ever implementation of
This beauty can be found in And the kicker? The function's documentation:
The author clearly knew that unknown methods* shouldn't be called… But instead of doing something sensible – like throwing an exception – they do something wholly nonsensical and return Next up: why implicit conversions from </rant> *: the magic PS: Instead of calling Tuesday, August 25. 2009Making Flex's PopUpMenuButton More HelpfulIf you're anything like me, you cringe every time you think about implementing a popup menu in Flex: the options, For example, Well, cringe no more! I've done a bit of hacking on the <mx:XML id="colors"> <colors> <color name="Red" rgb="0xFF0000" /> <color name="Green" rgb="0x00FF00" /> <color name="Blue" rgb="0x0000FF" /> </colors> </mx:XML> <HelpfulPopupMenu id="colorMenu" dataProvider="{colors}" labelField="@name" showRoot="false" /> <mx:Label color="{XML(colorMenu.selectedItem).@rgb}" text="You've chosen: {XML(colorMenu.selectedItem).@name}" /> Which can also be used to set a temporary default option: <mx:Script><![CDATA[ var people:Array = [ { name: "Bob", age: 16 }, { name: "Alice", age: 42 }, { name: "Jo", age: 31 } ]; ]]></mx:Script> <HelpfulPopupMenu id="peopleMenu" dataProvider="{people}" labelField="name" selectedItem="{ { name: '(select a person)', age: null } }" showRoot="false" /> <mx:Label visible="{ peopleMenu.selectedItem.age !== null }" text="That person is { peopleMenu.selectedItem.age } years old." /> Useful? I'd like to hope so. You can see a demo by clicking the image below (sorry, I don't actually know the first thing about embedding SWFs into HTML, and I don't feel up to learning right now): And you can download the source (which is MIT licensed) from more or less the same place: http://wolever.net/~wolever/HelpfulPopupMenu/. Also, this is a small part of a larger library of helpful ActionScript utilities which I'm going to be releasing… At some point. Tuesday, August 11. 2009Using Hamcrest to Filter ArrayCollectionsNeil Webb's post on filtering an ArrayCollection on multiple property/values reminded me of how I recently solved exactly the same problem using Hamcrest-AS3. So, you know the story: you've got an Because you're a good programmer you always try to do the simplest thing that could possibly work first, and end up with a function something like this:
Cool - that defiantly works, and it's pretty simple. "But wait a second", you're thinking, "what happens when the rules get more complex? That function is quickly going to loose its simplicity!" Enter, Hamcrest. Hamcrest is a library of "matchers" which are often used to build unit tests. Here is a quick example of a unit test written with Hamcrest:
But, of course, there is no reason that these same matchers shouldn't be used for other things too. Other things like, say, filtering an ArrayCollection:
Of course, I've hard-coded the values in this example, but it doesn't take much creativity to imagine how they could be dynamically generated, keeping the code nice and simple while still allowing for complex rules. So, that's how I filter ArrayCollections Friday, July 10. 2009Overriding private methods in ActionScript, the hard wayAre you working with a proprietary Continue reading "Overriding private methods in ActionScript, the hard way"
(Page 1 of 1, totaling 6 entries)
|
QuicksearchArchivesLinks
CategoriesSyndicate This Blog |
