User Tools

Site Tools


unit_test

This is an old revision of the document!


Source: Software Testing course at ITMO university by Kochubeev Nikolay Sergeevich

Unit tests

Unit tests check individual units of software (be it functions, methods or classes) in isolation from the rest of the system. The goal is to ensure that every module works as intended.

Concepts

Test doubles are used to ensure Unit tests are truly isolated.

Factories, builders and random-based tests are used to generate test data.

Benefits

  1. Units tests ensure quick feedback.
  2. They give confidence in refactoring.
  3. They document code's behavior.
  4. They can help find errors at the early stages.

Principles of good unit tests

  • FIRST: Fast, Isolated, Repeatable, Self-validating, Timely;
  • AAA: Arrange, Act, Assert;
  • GWT: Given-When-Then.

Pros and Cons

Pros:

  • quick feedback;
  • behavior documentation;
  • fast completion.

Cons:

  • do not test module interaction;
  • require support with changes to API;
  • do not find integration errors.
  1. JUnit (Java) – standard in the ecosystem, annotations, parametrization, Maven/Gradle and IDE integration.
  2. NUnit (C#) – flexible attributes ([TEST], [TestCase]), rich assert set.
  3. xUnit (.NET Core) – [Fact]/[Theory], modern style, .NET CLI integration.
  4. Go Testing (Go) – built-in, minimalistic, table-driven tests.
  5. pytest (Python) – fixtures, marking, parametrization, simplicity.
unit_test.1757445217.txt.gz · Last modified: by plida