Almost every software developer in an interview can tell you why testing is important, some might be able to explain what test-driven development is all about, but very few actually practice what they preach and almost none consistently have all test cases written before starting development.
Why? I guess human-beings are usually seeking instant satisfaction. In other words, we are instinctively short-sighted. With ever aggressive project timelines, time to delivery trumps quality almost every single time. The first thing sacrificed is not often the feature scope but thorough testing coverage of all features.
As a good software developer, we have to fight our instinct, the urge to crank out code and have something to show. For a POC [proof of concept], that might be acceptable, but for a sound product or a successful project, it is not.
Given certain extreme circumstance, we might have to cut corners… but not without a good fight. (Or when we know there is no chance to win the fight, as is the case in the Capital Markets where traders just can’t wait.) But when a corner is cut, a responsible developer who takes pride in his/her work knows something is missing, and a potential time-bomb is set to explode when a user keys in the unfortunate combinations.
Writing the tests first helps a developer write better code by forcing them to thoroughly understand the business requirement. If you don’t know how to write your unit test, how could you make sure all the common use cases, edge cases and error cases are covered by your code? Fine, maybe your brain can run as a computer and automatically run all the test cases through your code. In that case, write them down first so next time you need to modify the code, you can take it easy and let the computer run them for you.
The best experience I had was a 4 month project for a clearing house. We leveraged Cucumber testing framework, where we sketched out all the test cases before we wrote a single line of code. We did put in the API codes, and that’s about it.
At the beginning, you can imagine no test case would pass. With more features implemented, more and more test cases turned green. Sometimes we found we misunderstood the requirement, sometimes some new requirement or new constraints were thrown at us, but we always modified the test cases first. At the end, we had a good suite of regression tests to be integrated into the client’s infrastructure. And I had the peace of mind that as long as all the test cases passed, there is minimal risk that my code would break any existing behavior.
If you don’t have the luxury to write all the tests first, writing them afterwards may cost you a lot more, but in my opinion, is still well worth it. Our flagship product Validate.Trade, an increasingly popular tool adopted already by quite a number of elite banks to lower costs and improve regulatory compliance, did not have good testing coverage with the first release. A great effort was put in afterwards and as of now, we have roughly 163,000 test cases to cover all jurisdictions, asset classes, message types, and rules. We were able to collect test cases from clients during our evaluation phases, and can now automatically compare our Validate.Trade result and the DTCC GTR (UAT) result for the same test cases for every new build. This provides strong assurance that our software works and works as expected, although I am still not perfectly happy because we are not 100% covered! But, believe me, it will be done!
– Lixia Sun, Senior Partner, Trading Solutions
A note from Brian Lynch, Risk Focus CEO:
“Lixia Sun is a Risk Focus veteran and the Lead Architect and Developer of our Validate.Trade product. She is awesome and as you can see from this blog takes tremendous pride in her work. This is the type of commitment that has made Risk Focus a successful consulting firm in the Capital Markets and we are now applying this diligence to our Report-it.Trade software, a suite of components and services designed to improve the lives of everyone associated with Trade Reporting – Developers, Analysts, Operations and Compliance.”