views:

363

answers:

1

Recently, I've started to working on Email2SMS feature in our product. When I joined the project this component had zero code coverage by unit-tests. Legacy code.

Since I started to working on it, I was using test-first approach. But code quality was very low. It was very hard to split it and tests small chunks by unit-tests, so I decided to write integration test.

There is php script, which accepts some message info, search for user in DB and save some info if everything is OK.

$last_line = system('php emailtosms.php -file=unicode_message.txt ', $retval);

$this->assertStringExistsInLogFile('Email to SMS message was not sent');

Is it bad or not? How would you solve this problem?

+2  A: 

Not so good.

Test at a lower level, by having the emailtosms.php script as a simple wrapper that processes the command line args, and then pass off to more testable class. Depending on the final step, you could write unit tests to do almost every but the final send (maybe mock the final step that actually sends it, and just store it to a variable, then check you've got something valid there).

The final integration, runs the full class end-to-end, and check its output, looking at the final log - or a little higher-level, what would be put into to log.

Alister Bulman