MG Software.
HomeAboutServicesPortfolioBlog
Contact Us
  1. Home
  2. /Knowledge Base
  3. /What is Unit Testing? - Explanation & Meaning

What is Unit Testing? - Explanation & Meaning

Learn what unit testing is, how to test individual components with Jest, Vitest, or pytest, and why test coverage is essential for reliable software.

Definition

Unit testing is the testing of the smallest units of code, such as individual functions, methods, or classes, in isolation from the rest of the system. The goal is to verify that each unit works correctly according to its specification.

Technical explanation

Unit tests are the foundation of the testing pyramid and are executed most frequently. They should be fast, isolated, repeatable, and self-validating (FIRST principles: Fast, Isolated, Repeatable, Self-validating, Timely). Popular test frameworks include Jest and Vitest for JavaScript/TypeScript, pytest for Python, and JUnit for Java. Mocking replaces external dependencies (databases, APIs, file systems) with controlled simulations so tests only assess the unit under test. Spies monitor whether functions are called correctly. Test fixtures provide predefined test data. Test coverage measures what percentage of code is reached by tests: line coverage, branch coverage, and function coverage. Coverage of 80% is often considered good, but qualitative tests are more important than quantitative coverage. Parameterized tests run the same test with different input values. Snapshot testing compares output with previously captured references. Property-based testing generates random inputs to discover edge cases.

How MG Software applies this

MG Software writes unit tests for all business-critical code. We use Vitest for our TypeScript/React projects and pytest for Python services. Our CI/CD pipeline mandates minimum test coverage and blocks merges when tests fail. We combine unit tests with integration tests and end-to-end tests for complete system coverage.

Practical examples

  • A unit test verifying that a price calculation function returns correct results for regular prices, discounts, VAT, and edge cases like zero values or negative amounts.
  • An isolated test of an authentication service using a mock database, so the test runs fast and does not depend on a real database connection.
  • A CI/CD pipeline executing 500 unit tests in under 30 seconds on every commit, catching bugs immediately before code is merged.

Related terms

test driven developmentclean coderefactoringcontinuous deploymentcode review

Further reading

What is TDD?What is Clean Code?What is Continuous Deployment?

Related articles

What is an API? - Definition & Meaning

Learn what an API (Application Programming Interface) is, how it works, and why APIs are essential for modern software development and system integrations.

What is SaaS? - Definition & Meaning

Discover what SaaS (Software as a Service) means, how it works, and why more businesses are choosing cloud-based software solutions for their operations.

What is Cloud Computing? - Definition & Meaning

Learn what cloud computing is, the different models (IaaS, PaaS, SaaS), and how businesses benefit from moving their IT infrastructure to the cloud.

Software Development in Amsterdam

Looking for a software developer in Amsterdam? MG Software builds custom web applications, SaaS platforms, and API integrations for Amsterdam-based businesses.

Frequently asked questions

Test coverage of 70-80% is often considered good for most projects. But it is not just about the percentage: it is more important to cover critical paths, business logic, and edge cases than to chase 100% coverage. Some code (trivial getters, pure configuration) does not necessarily need to be tested.
A mock is a simulated object that defines expected behavior and verifies it is called correctly. A stub returns predefined values without verifying call behavior. A spy wraps a real implementation and records calls without changing behavior. In practice, the terms are often used interchangeably.
For JavaScript/TypeScript, Vitest is the modern choice with native ESM support and fast execution. Jest remains popular for existing projects. For Python, pytest is the standard thanks to its simple syntax and powerful fixtures. The choice depends on your technology stack and team preferences.

Ready to get started?

Get in touch for a no-obligation conversation about your project.

Get in touch

Related articles

What is an API? - Definition & Meaning

Learn what an API (Application Programming Interface) is, how it works, and why APIs are essential for modern software development and system integrations.

What is SaaS? - Definition & Meaning

Discover what SaaS (Software as a Service) means, how it works, and why more businesses are choosing cloud-based software solutions for their operations.

What is Cloud Computing? - Definition & Meaning

Learn what cloud computing is, the different models (IaaS, PaaS, SaaS), and how businesses benefit from moving their IT infrastructure to the cloud.

Software Development in Amsterdam

Looking for a software developer in Amsterdam? MG Software builds custom web applications, SaaS platforms, and API integrations for Amsterdam-based businesses.

MG Software
MG Software
MG Software.

MG Software builds custom software, websites and AI solutions that help businesses grow.

© 2026 MG Software B.V. All rights reserved.

NavigationServicesPortfolioAbout UsContactBlog
ResourcesKnowledge BaseComparisonsExamplesToolsRefront
LocationsHaarlemAmsterdamThe HagueEindhovenBredaAmersfoortAll locations
IndustriesLegalEnergyHealthcareE-commerceLogisticsAll industries