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:

  1. Arrange: set up the input, such as an order of ₹1,200.
  2. Act: call the function being tested.
  3. 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

LanguageTools
JavaJUnit, Mockito
C#xUnit, NUnit, Moq
Pythonpytest, unittest
JavaScriptJest, 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

Previous term: Trello  |  Next term: Unpaid Internship

Related guides

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
Dhaivat Ajwaliya

About the author

Dhaivat Ajwaliya

Dhaivat has 16+ years of experience in the IT industry, working on AI and cloud technologies, project delivery, and engineering leadership. He has interviewed and mentored many interns, wrote The Lost Intern, and runs the non-commercial Career Impact Initiative, mentoring students for free.