How to write unit tests for methods thsat echo instead of return (e.g., AJAX call handlers)
I'm a bit out of date on the current status of the civi test framework, but if WebTests are still available I would do this as a WebTest.
https://wiki.civicrm.org/confluence/display/CRM/Setting+yourself+up+to+work+with+Selenium+tests

Include a line that waits for some element you are expecting to appear, then test its value using the webtest api.