It is all eric's fault. He infected me with the TDD virus.
After being in the stormy Denmark (like Kris was a two years ago: http://blog.koehntopp.de/archives/941-Blavand-Strand.html ) and seeing the horses getting wet feet (high tide + storm == a lot of fun) I took some time to read "Test Driven Development" by Kent Beck.
The book is very easy to read as it goes tiny steps, very tiny ones. But it does it on purpose. It iterates over the basic principle again and again and again ... until you give up and just do it :)
It is formalizing your development into 4 steps:
- write a failing test (before you write code) (make it red)
- implement the most basic code to make it compile
- make it work (filling in real code) (make it green)
- remove duplication (refactor)
While it looks a bit wimpy to put a safe-guard in place before you do anything (real men don't need backups), it works. Doing refactoring without unit-testing is dangerous and having the unit-tests allows you to get a phone call and get interrupted while you work on something. First you model the idea into a test-case, then you implement it.
As a result we now have another implementation of the xUnit framework, just in LUA. (there are others, but the license of their code wasn't clear).
The progress was: 1. test your test-suite 2. mock a proxy and test the lua scripts directly without a proxy
$ make check -C tests/unit/lua/ 100.00%, 6 passed, 0 failed PASS: proxy-test.lua 100.00%, 5 passed, 0 failed PASS: active-queries.lua 100.00%, 2 passed, 0 failed PASS: proxy-auto-config.lua 100.00%, 9 passed, 0 failed PASS: proxy-commands.lua ================== All 4 tests passed ==================
These unit-tests for the lua-side of the proxy pair nicely with the other tests:
- the unit-tests for the C-layer
- the function tests for the proxy
- working against a real MySQL
- chaining proxies and their scripts
make: Entering directory `.../trunk/tests/suite' proxy.response.type is unknown: 25 ok raw_packets ok tokens1 ok tokens2 ok query_analizer1 ok error_struct ok chain1 ok bug_30867 ok xtab1 ok xtab2 ok resultset ok select_null ok select_affected_rows PASS: base ================== All 1 tests passed ================== make: Entering directory `.../trunk/tests/unit' Running suite(s): sql-tokenizer 100%: Checks: 3, Failures: 0, Errors: 0 PASS: check_sql_tokenizer Running suite(s): mysqld_proto 100%: Checks: 3, Failures: 0, Errors: 0 PASS: check_mysqld_proto Running suite(s): plugin 100%: Checks: 2, Failures: 0, Errors: 0 PASS: check_plugin ================== All 3 tests passed ==================