Unit Testing: Testing small pieces of code, such as a single function or class, on their own, usually with automated tests that run in seconds.
Example
You write a unit test that calls calculateDiscount(1200) and checks the result is 120, and another that checks orders below ₹1,000 get no discount. Both run every time anyone changes the code.
What a Unit Test Looks Like
Most unit tests follow three steps, often called Arrange, Act, Assert:
- Arrange: set up the input, such as an order of ₹1,200.
- Act: call the function being tested.
- Assert: check the result is what you expected, such as a ₹120 discount.
Dependencies such as databases or APIs are usually replaced with mocks, so the test checks only your logic.
Common Unit Testing Tools
| Language | Tools |
|---|---|
| Java | JUnit, Mockito |
| C# | xUnit, NUnit, Moq |
| Python | pytest, unittest |
| JavaScript | Jest, Vitest |
Good Unit Test Habits
- Test edge cases: empty lists, zero, null, very large values.
- One behaviour per test, with a clear name such as "noDiscountBelowThreshold".
- Keep tests fast and independent of each other.
- Add a test whenever you fix a bug, so it can't come back.
Unit tests in your GitHub project are a strong signal to interviewers that you write code carefully.
Related terms
- Integration Testing: tests several parts together.
- Test Case: a defined check, which unit tests automate.
- Code Quality: unit tests protect it.
- Continuous Integration (CI): runs unit tests on every change.
- Regression Testing: unit tests help catch regressions.
Previous term: Trello | Next term: Unpaid Internship
Related guides
- Software Development vs Testing
- Build a GitHub Portfolio That Gets You Internship Interviews
- Technical Interview Questions for Freshers
Frequently asked questions
What is unit testing?
Unit testing is testing small pieces of code, such as one function, on their own with automated tests.
Who writes unit tests?
Usually developers, as part of writing the feature.
What is mocking in unit testing?
Replacing real dependencies, such as a database, with fake objects so the test checks only your code's logic.
Should I add unit tests to my college project?
Yes. Even a few tests for the core logic show interviewers that you care about quality.
Explore more internship terms
The IT Internship Glossary explains 199 terms you will hear before and during your internship, with simple definitions and real examples.
Browse all 199 terms