Self-testing Software: A Paradigm Is Born (16 nov 10)
You are supposed to write the tests first, but suppose you didn't?
Suppose, hypothetically, you create a tightly-coupled server (eg. a Rails app), where you have to run it in order to test it, instead of starting with small, independently testable units?
I would never do that, but in case you made that mistake:
You can write tests which attempt to run the server first, like this: `/bin/ruby script/server -p 3001` then wait while it starts, then run the tests, then kill the server process: `kill -9 PID`
I didn't have much luck with that method
Instead, you can write a test method in the server, which runs tests after the server has started, if it is started with a parameter:
def Server::run
fork { puts `/usr/bin/ruby my_test.rb 2>&1` } if ARGV[0] == '--test' unless ARGV[0].nil?
# else... run normally
end