Skip to content
🛡️ FREE Master Frontend Security · All 7 modules live · 100% free Start free →

· software testing · 5 min read

Writing The Perfect Tests for your Application

Testing is hard, but knowing what and when to test is actually harder. Let me tell you about 3 types of tests that can help you secure your project.

Neciu Dan

Neciu Dan

Hi there, it's Dan, a technical co-founder of an ed-tech startup, host of Señors at Scale - a podcast for Senior Engineers, Organizer of ReactJS Barcelona meetup, international speaker and Staff Software Engineer, I'm here to share insights on combining technology and education to solve real problems.

I write about startup challenges, tech innovations, and the Frontend Development. Subscribe to join me on this journey of transforming education through technology. Want to discuss Tech, Frontend or Startup life? Let's connect.

Share:

We, as humans, are all looking for perfection. Some are trying to capture the perfect sunset, some are trying to ride the perfect wave and Software Engineers are looking for perfection in their code.

We want to write clean, maintainable code, with as little fragility as possible, and to achieve this most of the time the correct approach is with lots and lots of tests.

I wrote about the 5 types of testing practices you need in your application, but in this article, I want to talk about the app-saving tests, that can help you save time, money, and stress.

We can categorize the perfect tests into 3 types:

  • The test that helps you build
  • The test that helps you debug
  • The test that helps you sleep well at night

The Test that helps you Build

The Test that helps you build

Photo by Randy Fath on Unsplash

The purpose of Software Testing is to make sure our code works!

And it’s important our code works in as different situations as possible. Testing just the happy path is not enough, we have to add tests for boundary situations and errors.

For example, we have an array of numbers:

const arr = [1,2,3,4,5]

And we want to write a simple function that adds +1 to every number of the array without using any array build-in functions like map or reduce

If you start with a simple for loop from 0 to 5, iterate through the array, and add 1 to each value, we can create a boundary test where instead of passing a 5-value array we will pass a 6-value array or an empty array.

Our tests would fail, and we will improve our design by changing the for loop to include the array’s length.

We are continuously iterating through our design and building better and more maintainable code.

You write your tests first, make sure they fail and write the most straightforward code that will make your test case pass.

Afterward, you look at your code and see if it can be improved in any way, if not you add another test case and continue the cycle.

This is what Test-Driven-Development (TDD) is all about.

The Test that helps you debug

 The Test that helps you debug

Photo by Mediamodifier on Unsplash

Has this ever happened to you?

You’re working on your project and you find a critical bug that is hard to reproduce but you just know it wasn’t there in the last sprint.

It was introduced recently, but you don’t know how and more importantly when.

In October 2022, Git introduced a very handy command called git bisect

git bisect is a useful tool for quickly identifying the commit that introduced a bug in your code. It can save you a lot of time compared to manually searching through the commit history.

But before you run the git bisect process, you need a test to determine if the bug is present or not.

Let’s say you have a bug in the login flow. You would write an e2e that simulates the flow for you.

Having the test ready, here’s how to use it to find the commit that introduced a bug:

  1. Start the bisect process by running git bisect start.
  2. Identify a commit that is known to be “good”, and run git bisect good <commit>.
  3. Identify a commit that is known to be “bad”, and run git bisect bad <commit>.
  4. Git will then check out a commit that is halfway between the good and bad commits.
  5. Run your test to determine whether the current commit is good or bad. If it is good, run git bisect good. If it is bad, run git bisect bad.
  6. Repeat this process until git bisect finds the commit that introduced the bug.
  7. When git bisect has found the commit, it will output the commit hash and message.
  8. Run git bisect reset to stop the bisect process and return to the HEAD commit.

Automating this process will save you hours and hours of checking commit histories, especially if the bug was introduced months ago and you have a very big codebase.

The Test that helps you Sleep well at night

The Test that helps you Sleep well at night

Photo by bruce mars on Unsplash

Engineers love complexity.

Like building software that does things, nobody or no other software has done before.

And the same is true for our automation processes. Engineers like to add automated flows for visual tests, performance tests, unit tests, and every other kind of testing flow imaginable.

I actually wrote a piece about 5 testing practices you should have in your CI/CD pipeline, but the truth of the matter is that a very simple synthetic test would give you more value than all of those combined.

Sure, testing practices in your CI/CD can prevent faults from being deployed, but bugs are tricky, they like to hide in dark places and only come out during the perfect moment (Like a long weekend, or Christmas)

Having a smoke test or a synthetic test that covers the most critical business flow in your application running on the production environment, will give everyone involved that amazing good night’s rest without worrying about the feature they deployed on Friday.

Third-party monitoring and observability tools like DataDog, Sentry, or Testing as Service platforms allow you to build these kinds of tests that run on your application every minute and alert you if anything goes wrong.

Building these tests in your pipeline, having canary deployments, and running them only on the affected group could save your company a lot of money and reduce the stress level of all the company’s engineers.

Conclusion

Software Testing is not only useful to verify the correctness of your software.

Taking full advantage of tests you can use them to better write your code using TDD practices like Red-Green-Refactor or Triangulation.

You can automate debugging with git bisect and a handy E2E test to quickly find when a bug was introduced in your codebase.

And having a small and simple synthetic test that runs on your production environment can make sure your dreams at night are without worry and stress.

Doesn’t that sound just perfect?

🛡️ FRONTEND SECURITY · REACT · VUE · ANGULAR · VANILLA JS

Master Security in Frontend Applications

Free, comprehensive frontend security course.
XSS, CSRF, AI security, broken access control & the vulnerabilities that actually get you breached.

100% FREE 7 MODULES · ALL LIVE
Start learning free →

All 7 modules live now. No credit card.

Neciu Dan

Discover more from The Neciu Dan Newsletter

A weekly column on Tech & Education, startup building and occasional hot takes.

Over 1,000 subscribers

🎙️ Latest Podcast Episodes

Dive deeper with conversations from senior engineers about scaling applications, teams, and careers.

Accessibility at Scale with Craig Abbott
Episode 48
59 minutes

Señors @ Scale host Neciu Dan sits down with Craig Abbott, Principal Accessibility Specialist at TetraLogical and the former Head of Accessibility at the UK's Department for Work and Pensions, one of the largest government departments in the country, where he built a dedicated accessibility practice from nothing and open sourced the DWP Accessibility Manual. Craig has over 15 years in user centred design and has led accessibility work across the public sector and at Elastic. From what sustainable accessibility actually means and why third party audits alone don't get you there, to the three C's of compliance, culture and capability, to running screen readers in VMs without expensive licences, to accessibility acceptance tests in CI with Playwright, Cucumber and Guidepup, to why compliance does not mean usable, this is the accessibility conversation for teams who want it to survive the person who cares about it.

📖 Read Takeaways
Versatility at Scale with Carmen Huidobro
Episode 47
42 minutes

Señors @ Scale host Neciu Dan sits down with Carmen Huidobro, CTO at Incredible Bee in Vienna, where she builds products and helps teams figure out what should be automated and what should stay in the hands of users. Carmen has spent 17 years in tech, almost all of it freelancing, working across Objective-C, Ruby on Rails, the web, mobile, hardware, and even ABAP inside an SAP consultancy, plus five years in developer relations and developer education. Her argument is that the generalist versus specialist debate misses the point: the durable skill is being an expert at adapting. From adding a local Mistral model to a twenty-year-old macOS app without betraying the people who use it, to the refugee hackathon project the City of Vienna still runs a decade later, to why she won't take money from junior developers, this is a conversation about the skills that survive the shift.

📖 Read Takeaways
CI/CD at Scale with Marko Gacesa
Episode 46
45 minutes

Señors @ Scale host Neciu Dan sits down with Marko Gaćeša, Head of Product at Semaphore, the agent-native CI/CD platform, and the first product guest on the show. Marko is a serial entrepreneur whose career spans developer tools, IoT, industrial automation and enterprise SaaS, including founding Dry Tools and serving as Chief Product Officer at Alchemy Cloud, with earlier work in domains like medical equipment where quality is non-negotiable. From why testing rather than coding is now the bottleneck, to what agent-native CI/CD actually means when developers live inside their coding agent, to how SemAI attacks flaky tests and automates migration off GitHub Actions, to pricing a platform where a minute of CI is not the same minute everywhere, this is the product side of developer tooling from someone shipping it.

📖 Read Takeaways
AI Harness at Scale with Maxim Salnikov
Episode 45
44 minutes

Señors @ Scale host Neciu Dan sits down with Maxim Salnikov, AI Dev Tools Solution Engineer at Microsoft, where he leads AI native development enablement for over 100 enterprise customers of Microsoft and GitHub in Norway. Maxim has been building for the web since the late 90s and spends his days inside real enterprise dev teams across finance, energy, agriculture, and pure software companies, watching AI adoption succeed and fail. From why adoption is a change management problem rather than a technology one, to the anatomy of an AI harness and the external layer successful companies build on top of it, to the context engineer and agent ops roles now appearing in team topologies, to managing agent skills as versioned dependencies instead of letting them pollute the repo, this is the enterprise AI adoption conversation from someone who sees a hundred versions of it.

📖 Read Takeaways
Back to Blog