惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
WordPress大学
WordPress大学
U
Unit 42
I
InfoQ
A
About on SuperTechFans
宝玉的分享
宝玉的分享
J
Java Code Geeks
博客园 - 司徒正美
爱范儿
爱范儿
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
腾讯CDC
Recent Announcements
Recent Announcements

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Testing Discipline: A Beginner's Guide
Favor Charles Owuor · 2026-06-01 · via DEV Community

18824957
Image by upklyak on Magnific


Run an application. Click a few buttons. If the terminal doesn't have errors, then everything is working. Right?

What's the point of writing tests if all seems to be fine. Let's explore testing discipline and why it's a habit every developer should build early.


What is Testing Discipline?

Testing discipline is the habit of verifying that your code works. It's not something you do at the end of a project.
It's something you build into your development process.

The goal is simple. Catch bugs as early as possible. A bug found while writing code usually takes minutes to fix.

The same bug found in production can take hours to investigate, reproduce, and resolve.

The earlier you find problems, the less expensive they become.


Different Types of Tests

When people talk about testing, they're usually referring to three categories.

The first is unit testing. A unit test checks a single piece of functionality, usually a function or method. These tests are fast and easy to write, making them the best place for beginners to start.

Next are integration tests. These verify that different parts of your application work together correctly. For example, does your service communicate properly with the database?

Finally, there are end-to-end tests. These simulate a real user interacting with the application from start to finish. They provide the most realistic results but are usually slower and more complex.

As a beginner, I recommend that you should focus on unit tests first.


Different Testing Approaches

As you continue learning, you'll come across different testing methodologies.

One of the most popular is Test-Driven Development, often called TDD.

The idea is simple. Write the test first. Watch it fail. Write enough code to make it pass.

Many developers like this approach because it forces them to think about requirements before writing implementation details.

You may also hear about Behaviour-Driven Development, or BDD.

This approach focuses on describing behaviour in a way that both technical and non-technical people can understand.

Then there is static testing and dynamic testing.

Static testing involves reviewing code without running it. Code reviews and linters fall into this category.

Dynamic testing involves running the application and verifying its behaviour.

Both have their place in a healthy development process.


Writing Tests in Go

One thing I like about Go is that testing support is already built into the language. You don't need to install any package just to write your first test.

There are a few rules to remember.

  1. Test files must end with _test.go.
  2. Test functions must begin with Test.
  3. They must also accept a *testing.T parameter.

For example:

func TestCalculateDiscount(t *testing.T) {
    // test logic
}

Enter fullscreen mode Exit fullscreen mode

Once you follow those rules, Go automatically recognizes your tests.


A Simple Example

Imagine you're building an e-commerce application.

You have a function that calculates discounts based on order value.

Your code works for normal orders, but what happens if someone enters a negative amount?
What happens at the discount threshold?
What happens for large purchases?

These are the kinds of questions tests help answer.

A common pattern in Go is called table-driven testing.

Instead of writing separate tests for every scenario, you place inputs and expected outputs into a table and loop through them.

This allows you to test multiple situations without repeating large amounts of code.

It's one of the most common testing patterns you'll see in Go projects.


Running Tests

Once you've written a test, running it is simple.

To run all tests:

go test

Enter fullscreen mode Exit fullscreen mode

To see detailed output:

go test -v

Enter fullscreen mode Exit fullscreen mode

To check test coverage:

go test -cover

Enter fullscreen mode Exit fullscreen mode

When you're starting out, go test -v is usually the most helpful because it shows exactly which tests passed and which failed.


Making Testing Part of Your Workflow

Writing a few tests is useful. Whenever you add a feature, write tests for it.
Whenever you fix a bug, consider adding a test that prevents the same bug from returning.

Over time, your test suite becomes a safety net.
You can refactor code, improve performance, and add features with much more confidence because the tests will alert you if something breaks.

This becomes even more important when using CI/CD pipelines.
Tests can run automatically whenever code is pushed, helping catch issues before they reach production.


Why Testing Matters

I know testing can feel slow at first.
When you're excited about building features, writing tests can seem like extra work.

But after spending hours debugging issues that a simple test could have caught in seconds, my perspective changed.

Tests give you confidence.
They make refactoring safer.
They help identify bugs quickly.
They also act as documentation by showing exactly how a function is expected to behave.
Most importantly, they help you deliver software that actually works.


Conclusion

Many beginners see testing as something they'll learn later.
The truth is that testing is one of the habits that helps you grow from a beginner into a reliable developer.
You don't need to test everything immediately.

Pick a function you've already written and create a few test cases for it.
Test the normal case.
Test an edge case.
Test an error case.
Run the tests and see what happens.

The more often you do this, the more confidence you'll have in your code and the less time you'll spend chasing bugs in production.