|
From: Darren C. <da...@dc...> - 2006-05-26 08:35:19
|
I finally found time to get back to the project I want to unit test, and
hit a bump when testing for an expected NaN.
I was going to propose extending assertEquals to handle NaN as a special
case but convinced myself that examples like this make that a bad idea:
assertEquals("should this pass when x==0?", x/1, x/2);
So I wrote assertIsNaN(); I was going to send a patch but it is so short
that I just included it below. It goes somewhere in Assert.as (only
tested on as2 branch).
If you want a proper patch let me know.
Darren
/**
* Asserts that assertion isNaN(); any valid number or any other
* type of object will fail the test.
*/
public static function assertIsNaN(msg:Object, assertion:Object):Void {
if(arguments.length == 1) addTestResult("", "assertIsNaN", isNaN(msg));
else addTestResult(String(msg), "assertIsNaN", isNaN(assertion));
}
|
|
From: Darren C. <da...@dc...> - 2006-05-26 09:04:21
|
> I was going to propose extending assertEquals to handle NaN as a special > case but convinced myself [otherwise]: I'm unconvinced again. I cannot assert on an array that contains some NaNs: SMA(2) of bad data expected:<,0,0,NaN,NaN,NaN> but was:<,0,0,NaN,NaN,NaN> What do other people think? Darren |
|
From: Luke B. <lb...@gm...> - 2006-05-27 05:20:08
|
I recognize this may sound strange coming from one of the authors of AsUnit= , but I have to confess that the only assertion I really use is assertTrue. Occasionally, I've found assertNull and assertFalse useful, but the overwhelming majority of my test cases have nothing but a bunch of assertTrue statements. As an example, our latest project has 607 instances of the "assertTrue" string. I guess this why we went out and bought the domain... http://www.asserttrue.com Does anyone else do this? Or is this just another way in which I'm kind of strange? ;-) Luke www.asunit.org |
|
From: Jan H. <za...@ar...> - 2006-05-27 10:14:40
|
Well, I must admit that's also my way of unit testing.... grep -R assert * | wc -l 3774 grep -R assertTrue * | wc -l 3754 In 99.5 % of the cases I don't need anything but assertTrue ;-) Jan On 27-Mai-2006, at 07:20, Luke Bayes wrote: > I recognize this may sound strange coming from one of the authors > of AsUnit, but I have to confess that the only assertion I really > use is assertTrue. Occasionally, I've found assertNull and > assertFalse useful, but the overwhelming majority of my test cases > have nothing but a bunch of assertTrue statements. As an example, > our latest project has 607 instances of the "assertTrue" string. > > I guess this why we went out and bought the domain... > > http://www.asserttrue.com > > Does anyone else do this? Or is this just another way in which I'm > kind of strange? > > ;-) > > > Luke > www.asunit.org > > _______________________________________________ > Asunit-users mailing list > Asu...@li... > https://lists.sourceforge.net/lists/listinfo/asunit-users |
|
From: Darren C. <da...@dc...> - 2006-05-27 21:52:19
|
> but I have to confess that the only assertion I really use is assertTrue. > Occasionally, I've found assertNull and assertFalse useful... I think assertEqual is more useful than assertTrue as you are able to tell the framework more information. And that means it can give you a more useful error message. E.g. assertTrue(Math.PI=3.14); assertEqual(Math.PI,3.14): All the first one can say is "it is false". The second one can say "3.14 is not equal to 3.1415932142143" (or whatever PI actually is :-). That means I get to see exactly what the bug is, immediately. Also, after my recent patch, assertEqual is also more useful in that it compares arrays and objects (and recursively); something you cannot do with assertTrue and either == or ===. Darren , but the > overwhelming majority of my test cases have nothing but a bunch of > assertTrue statements. As an example, our latest project has 607 instances > of the "assertTrue" string. > > I guess this why we went out and bought the domain... > > http://www.asserttrue.com > > Does anyone else do this? Or is this just another way in which I'm kind of > strange? > > ;-) > > > Luke > www.asunit.org > > > ------------------------------------------------------------------------ > > _______________________________________________ > Asunit-users mailing list > Asu...@li... > https://lists.sourceforge.net/lists/listinfo/asunit-users |
|
From: Peter H. <pet...@gm...> - 2006-05-29 18:40:38
|
I use assertEqual and assertSame a lot. You get much better error messages. Peter. On 5/27/06, Darren Cook <da...@dc...> wrote: > > > but I have to confess that the only assertion I really use is > assertTrue. > > Occasionally, I've found assertNull and assertFalse useful... > > I think assertEqual is more useful than assertTrue as you are able to > tell the framework more information. And that means it can give you a > more useful error message. > > E.g. > assertTrue(Math.PI=3D3.14); > assertEqual(Math.PI,3.14): > > All the first one can say is "it is false". The second one can say "3.14 > is not equal to 3.1415932142143" (or whatever PI actually is :-). That > means I get to see exactly what the bug is, immediately. > > Also, after my recent patch, assertEqual is also more useful in that it > compares arrays and objects (and recursively); something you cannot do > with assertTrue and either =3D=3D or =3D=3D=3D. > > Darren > > > , but the > > overwhelming majority of my test cases have nothing but a bunch of > > assertTrue statements. As an example, our latest project has 607 > instances > > of the "assertTrue" string. > > > > I guess this why we went out and bought the domain... > > > > http://www.asserttrue.com > > > > Does anyone else do this? Or is this just another way in which I'm kind > of > > strange? > > > > ;-) > > > > > > Luke > > www.asunit.org > > > > > > -----------------------------------------------------------------------= - > > > > _______________________________________________ > > Asunit-users mailing list > > Asu...@li... > > https://lists.sourceforge.net/lists/listinfo/asunit-users > > > > _______________________________________________ > Asunit-users mailing list > Asu...@li... > https://lists.sourceforge.net/lists/listinfo/asunit-users > |
|
From: Chris A. <mrc...@gm...> - 2006-05-30 13:15:03
|
I agree with Darren and Peter in that I try to use the most specific assertion method for what I'm trying to test. The error messages that are returned should let me know more about what failed as opposed to having to look at my code and see what I tested where assertTrue failed. This is the reason that I suggested that you add assertNullValue() because it will test for obj === null; and obj === undifined. Plus, typing assertNullValue(obj); is quicker to type and easier to read than: assertTrue(obj === null || obj === undifined); -Chris On 5/29/06, Peter Hall <pet...@gm...> wrote: > I use assertEqual and assertSame a lot. You get much better error messages. > > Peter. > > > On 5/27/06, Darren Cook < da...@dc...> wrote: > > > but I have to confess that the only assertion I really use is > assertTrue. > > > Occasionally, I've found assertNull and assertFalse useful... > > > > I think assertEqual is more useful than assertTrue as you are able to > > tell the framework more information. And that means it can give you a > > more useful error message. > > > > E.g. > > assertTrue(Math.PI=3.14); > > assertEqual(Math.PI,3.14): > > > > All the first one can say is "it is false". The second one can say "3.14 > > is not equal to 3.1415932142143 " (or whatever PI actually is :-). That > > means I get to see exactly what the bug is, immediately. > > > > Also, after my recent patch, assertEqual is also more useful in that it > > compares arrays and objects (and recursively); something you cannot do > > with assertTrue and either == or ===. > > > > Darren > > > > > > , but the > > > overwhelming majority of my test cases have nothing but a bunch of > > > assertTrue statements. As an example, our latest project has 607 > instances > > > of the "assertTrue" string. > > > > > > I guess this why we went out and bought the domain... > > > > > > http://www.asserttrue.com > > > > > > Does anyone else do this? Or is this just another way in which I'm kind > of > > > strange? > > > > > > ;-) > > > > > > > > > Luke > > > www.asunit.org > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Asunit-users mailing list > > > Asu...@li... > > > > https://lists.sourceforge.net/lists/listinfo/asunit-users > > > > > > > > _______________________________________________ > > Asunit-users mailing list > > Asu...@li... > > https://lists.sourceforge.net/lists/listinfo/asunit-users > > > > > > > _______________________________________________ > Asunit-users mailing list > Asu...@li... > https://lists.sourceforge.net/lists/listinfo/asunit-users > > > |