Skip to content

Use of mock objects for testing purposes #220

Open
@bonaparten

Description

@bonaparten

In order to test a unit of the ohsome API, we need to create all the java objects needed for the test even if the dependencies themselves are not the purpose of the test. Using some frameworks (e.g. Mockito) in order to create mock objects could make tests more flexible and easier to handle.
There are lots of use cases where creating mock objects could make things easier. One simple example:

public class GeometryBuilderTest {

  @Mock
  InputProcessor mockProc;
  
  // Since we mock the InputProcessor object we don't need to define a ProcessingData object at all
  // private ProcessingData processingData = new ProcessingData(null, null);

  @Test(expected = BadRequestException.class)
  public void createPolygonFromGeoJsonWithWrongFormat() {
    String geoJson =
        "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"MultiPolygon\",\"coordinates\":"
            + "[[[[8.2944706,49.4313443],[8.2943343,49.4311946],[8.2942287,49.4313051],"
            + "[8.2942929,49.4313993],[8.2940648,49.4314931],[8.2931602,49.4328216],"
            + "[8.2933214,49.4329125],[8.2936734,49.4330121],[8.2940745,49.4331354],"
            + "[8.2950478,49.4317345],[8.2944706,49.4313443]]]]}]}";
    // InputProcessor inputProcessor = new InputProcessor(processingData);
    // geomBuilder.createGeometryFromGeoJson(geoJson, inputProcessor);
    geomBuilder.createGeometryFromGeoJson(geoJson, mockProc);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    brainstormingIdea for a potential new feature or adaption that still needs further discussioncomments welcomeIndicates that the creator of this issue/PR is open for early review comments

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions