Versions Compared

Key

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

...

Geode is tested with a combination of junit, dunit (distributed unit) and regression tests. Junit JUnit tests are written as with any other project while dunit DUnit tests use a multi-JVM environment (see Distributed Unit Tests).

JUnit tests shouldare divided into two main categories: UnitTest and IntegrationTest.

1. UnitTest: is a test with very narrow and well defined scope. Any complex dependencies and interactions are stubbed or mocked.

  • Should use JUnit 4 syntax
  • File name ends with *Test
  • Should use Category annotation of type UnitTest
  • Should complete in milliseconds 
  • Should generally test a single class
  • Typically uses white-box testing, uses Mocks/Fakes and helps guarantee internal quality (quality of code and class design)
  • Follows "A Set of Unit TestingRules" by Michael Feathers
    • A UnitTest should not do any of the following:
      • communicate with a database
      • communicate across the network
      • access the file system
      • prevent the running of other unit tests in parallel
      • require anything special in the environment (such as editing config files or running an external process)

2. IntegrationTest: a test involving inter-operation of components or subsystems.

  • Should use JUnit 4 syntax
  • File name ends with *IntegrationTest
  • Should use Category annotation of type IntegrationTest
  • May take longer than a UnitTest but should generally complete in seconds
  • May test a single class or any combination of classes including end-to-end testing of Geode
  • Typically uses black-box testing but may include some white-box testing and helps guarantee external quality (feature delivers value to User)
  • An IntegrationTest may do any of the following:
    • communicate across the network
    • access the file system
    • require anything special in the environment (such as editing config files or running an external process)

DUnit tests are a special type of JUnit test involving multiple JVMs. This effectively supports writing tests for a Geode cluster. The main category is DistributedTest.

3. DistributedTest: a test involving multiple members of a distributed system.

  • Should use JUnit 4 syntax
  • File name ends with *DistributedTest or *DUnitTest
  • Should use Category annotation DistributedTest
  • Should generally complete in seconds
  • May test interactions between multiple JVMs in a Geode cluster or via networking or via file system
  • Typically uses black-box testing but may include some white-box testing and helps guarantee external quality (feature delivers value to User)
  • A DistributedTest may do any of the following:
    • communicate across the network
    • access the file system
    • require anything special in the environment (such as editing config files or running an external process)

Regression tests are typically an IntegrationTest or DistributedTest written to reproduce a specific bug and verify the fix of that bug.

4. RegressionTest: an IntegrationTest or DistributedTest that reproduces a specific bug and verifies its fix.

  • Should use JUnit 4 syntax
  • File name ends with *RegressionTest
  • Should use Category annotation of type IntegrationTest or DistributedTest
  • Should follow guidelines of either Integration or DistributedTest
  • Should have Javadocs on the test class that reference the bug and describe it sufficiently without having to look up the bug in JIRA
  • May use black-box or white-box testing to guarantee that a bug has been fixed and will not be reintroduced without causing this test to fail

The following is the primary list of testing frameworks and libraries used in Geode tests (all of the above test categories):

  • JUnit 4
  • System Rules – powerful set of JUnit 4 Rules
  • AssertJ – richer than JUnit 4 Assert and includes better support for expected exceptions
  • Awaitility – useful for awaiting asynchronous conditions
  • Mockito – preferred over all other mocking libraries
  • JUnitParams – provides test method parameterization
  • Catch-Exception – better support for expected exceptions especially with complex nesting of exceptions or exceptions with unusual APIs
  • PowerMock – use this as a last resort – refactoring code to facilitate better testing is preferred
  • Use Junit 4 Syntax
  • End with JUnitTest
  • Contain an Category annotation of either UnitTest or IntegrationTest. UnitTests as should complete in milliseconds and test a specific class.

Always write unit tests for new functionality and always ensure that all unit tests pass before submitting a pull request. Try to make sure new functionality is covered by unit tests, whether or not there are also integrations integration tests as well.

./gradlew build

...