Complete
over 3 years ago

WERETECH-12565

This can already be done by changing the assert to

Test.assertEqualMessage(
    needle(),
    "haystack",
    needle() + " != haystack"
)

Test.assertEqualMessage and friends to show incorrectness

I would like to propose a feature for certain test methods that currently exist:

Test.assertEqualMessage(
  needle(),
  'haystack',
  "Found needle in the haystack"
)

When this fails we see the following when the testsuite has ran:

Error: Unhandled Exception
Exception: ASSERTION FAILED: ... Found needle in the haystack
Stack: 
  - assertMessage() at D:\grmn\prj\di\connectiq\toolchain\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\Test.mb:186 0x30001f4a 
  - assertEqualMessage() at D:\grmn\prj\di\connectiq\toolchain\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\Test.mb:243 0x30001f9f 

It would be very helpful to see what the needle was if it didn't compare against the haystack.  Now you need to print lines to debug this and well, I think the test method should take care of that debugging side of things.

  • See how easy Perl makes this, no need to dumping your vars in the message:

    is("foo", "bar", "not eq");
    
    #   Failed test 'not eq'
    #   at t/foo.t line 4.
    #          got: 'foo'
    #     expected: 'bar'

  • While you can print stuff in the message, consider this:

    Test.assertEqualMessage(foo(), 1, "The player has scored");
    Test.assertEqualMessage(bar(), 2, "... and so has player other");
    

    I don't want to print needle and haystack in every message in my test suite. You could argue it violates the DRY principle. Aka, your solution is ugly.