AS3 doesn't have static method imports as nice as Java 5, but we can do much the same thing with package-level functions.We could use these to cut down on the amount of typing necessary in FlexUnit 4.
I added this to my fork of AsUnit:
http://github.com/robertpenner/asunit/commit/bdb293436491792625ddc1f637c81c72398 6b87d
Example:
package asunit.asserts {Suggestion: package-level assert...When you have a moment, take a look at the assertThat() method and the new hamcrest matchers. I like these because rahter than build a single static class with all of the methods they distribute that work and allow (again with the theme) a pluggable way to handle comparison. This is defined as a top-level method of sort so that you have some less typing, altough adding back the complexity of hamcrest likely makes it equal.
Incidentally, I am guessing you could make your ASUnit fork work inside of FU4 in a matter of hours.
Mike
Suggestion: package-level assert...Right, I'm familiar with Hamcrest. I did my own AS2 port from Java because I liked it so much. But even so, I find myself staying with classic assertEquals() (in AsUnit 3) when I can, because I don't have to do the Hamcrest import and set up the swc for the project. Lazy, I know. I should put those things in templates. Also, assertEquals() will run faster, but how much difference that makes, I don't know, would have to measure.
JUnit 4 does it like this, and saves its users a lot of typing in the 80% case where no matchers are needed.
http://www.devx.com/Java/Article/31983/1763/page/2
import static org.junit.Assert.*;
...@Test
?public void add() {
?calculator.add(1);
?calculator.add(1);
?assertEquals(calculator.getResult(), 2);
?}
Another practical benefit for FlexUnit 4 users would be in migration. They wouldn't have to search and replace all their asserts in order to use the new test format.
Robert
I totally agree with you. I wish we had static imports as well.
Let's talk more about your suggestion, I am certainly open to it.
No comments:
Post a Comment