0

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.

j-p
  • 3,698
  • 9
  • 50
  • 93

1 Answers1

3

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.

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • thanks adam, Yes, Im trying to 'formalize' my unit testing with tools, I've always written homegrown test pages as 'pseudo-suites' - I'll look into testBox. Can you be kind enough to mention a few approaches "by name", if xUnit type testing is passe. Thx again – j-p Aug 04 '15 at 06:07
  • 1
    Well TestBox will use the notion of BDD-style tests, but I think that's mostly a misnomer (although one that has industry traction) and I generally try to avoid the term. In the CFML world there's only really the options of xUnit and TestBox's "BDD style". If you want to ask questions, can I recommend you join the CFML Slack Channel (subscription links in this blog article: http://blog.adamcameron.me/2015/06/cfml-slack.html. There is a subchannel there for TestBox. – Adam Cameron Aug 04 '15 at 08:20