Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a class that mirrors the package structure of your testee, call the class like the Testee and put Test at the end. Normal source code belongs in the src folder, test code go to the test folder (the test for info.inspectit.service.VersionService is thus info.inspectit.service.VersionServiceTest)
  2. Extend from info.novatec.inspectit.testbase.TestBase
  3. Each method should test exactly one situation, prefer to write more test methods than to have everything within one method

Here is an example:

...

The VersionService uses a VersionProvider (info.novatec.inspectit.version.VersionProvider) to  to retrieve the current version. The Provider is responsible for retrieving the version in some way and returning the string back to the version service which will build up a nice representation of the version (or throw exceptions if the version is invalid).

  •  finalize the documentation on how to write unit tests as soon as versioning is checked in Stefan Siegl

...

Realizations can be for example the FileBasedVersionReader

The VersionServiceTest mirrors the package structure of the VersionService. It extends TestBase. The Versionservice is responsible for caching the version lookup, so one test method checks that correct versions are cached. To do that the VersionProvider is mocked. Notice the InjectMocks annotation on the versionService (the testee) to integrate all mocks automatically.