MXunit testing for type of boolean

116 Views Asked by At

I think I need to test for a return type of boolean as a first test. How would I do this?

for any method that returns a boolean such as

public boolean function isValid( required numeric id ) {
    // returns 'true' if data is valid, 'false' if data is not valid
}

there are; assertIsQuery and assertIsStruct ... I think I'm looking for something like assertIsBoolean and since there isn't that method, the closest is

assertIsTypeOf

but I do not know what syntax to use to test boolean 'type' - and is seems as though test assertTrue or assertFalse are not what I'm looking for.

1

There are 1 best solutions below

2
On

Well are you testing whether it's a boolean, or whether it's true or false? it's far more common to be testing it's the latter, in which case you'd use assertTrue() or assertFalse() as appropriate.

If you really need to test whether it's a boolean irrespective of value, then just use isBoolean() in an assertTrue():

assertTrue(isBoolean(result));

BTW, it sounds like you're just starting out with testing, if so: it's perhaps best to not use MXUnit which is pretty much a dead project. Use TestBox instead. It is actively supported, is MXUnit-compatible to facilitate migration away from xUnit style testing, and leverages more modern approaches to writing tests.