Skip to content


There comes a time in a developer's adventure where he or she will stumble upon a testing framework and think, "Tests are a great idea, I should start writing them." But in my case, I begin to realize that starting to write tests can be challenging. This is usually due to multiple reasons including having to restructure one's code, what to test, mocking external services, etc. And with that list of reasons, I start to rationalize that maybe skipping tests is okay, since it seems like a huge upfront cost and a bit of overhead for unknown value. If I would have known years ago what I know now, I would have told myself that the rationalization is ridiculous and just start writing tests because they are totally worth it.

So where does the most value come from in tests for me? As important as it is to test the normal scenarios in my domain code logic, I find that it is even more important to test invalid scenarios in my domain. Does my code reject invalid inputs correctly and gracefully? Did I make sure to cover all possible scenarios that include invalid ones? These things are boring to manually test every time and over time, I will start to assume that it will always work this way in the future. That is a dangerous mindset to get into, as I will make a small change somewhere in the code that will change the assumptions that the existing code has and because of that, it will most likely introduce bugs or security issues.

With that said, I plan to write a series about how I write code and tests. But until those are published here, I will leave you with some probably obvious but solid advice about writing tests. It's good to have many small tests, and test the smallest bit of code that is possible. I personally haven't written any big tests but I can imagine that the bigger the test scenario, the more likely that the test code will need to be updated if the domain rules change. Focus the tests on the domain rules and logic. It's not very interesting to test code that saves some data to a persistent storage like a database, and avoiding these kind of tests makes it easier to have mock objects for things like persistent storage.


Display comments as Linear | Threaded

Joshua Szanto on :

Testing can be both fun and boring. At work I've built an automation script that utilizes the RMM's scripting engine along with PowerShell and Batch. It's a very complex script with many moving pieces. The root behind testing and debugging is to test for contingencies, but then it becomes a question of to what scope you test for - a subconscious search for balance between over-testing and under-testing for every element. Time is one factor; you can spend an eternity testing your product and still find bugs, so when testing for specifics, failures, and other test points - what is practical? Perhaps one may consider to test some parts of a design more synthetically with unnaturally high standards (with anticipation that real world results would be rock solid), but other things are not like that (particularly the unknowns, things that could go wrong that you haven't thought of). I think the latter are the hardest to test for (including determining if it is reasonable or not), and some of these seem to come out during 5000-10000ft testing and are a bane to solve at times.

I can definitely attest to testing smaller pieces. If the smaller pieces are rock solid, then you have an improved insight in what to look for when testing at 2500ft, 5000ft, and 10000ft levels.

Add Comment

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options

Submitted comments will be subject to moderation before being displayed.