Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

General

  • Tests should not be public

  • If tests throw any exception, they must throw Exception.class only

  • Testclass name pattern:

    • rest: Start with the name of the tested class or description of the tested behavior, end with “IntTest” or “RestDocTest”, e.g. TaskControllerIntTest

    • lib: Start with the name of the tested class or description of the tested behavior, end with “AccTest”, e.g. UpdateTaskAccTest

  • Assertions

    • We are using AssertJ only

    • Concatenate the assertions if possible

    • We are strictly using the AssertJ fluent syntax. This means assertThat(<testObject>).<operation>
      examples:
      BAD: assertThat(string.contains(“foo”)).isTrue();
      GOOD: assertThat(string).contains(“foo”);
      General Rule: Do not use any operation within the assertThat() function. Use existing functions from AssertJ’s assert classes.

    • We want to use extracting instead of explicit extracting for collection-type entities.

      • e.g.

        assertThat(events)
            .extracting(WorkbasketHistoryEvent::getEventType)
            .containsExactly(WorkbasketHistoryEventType.DISTRIBUTION_TARGET_ADDED.getName());

        instead of

        type = events.get(0).getEventType();
        assertThat(type).isEqualTo(WorkbasketHistoryEventType.DISTRIBUTION_TARGET_ADDED.getName());

Unit Tests

  • Test name pattern: should_ExpectedBehavior_When_StateUnderTest or should_ExpectedBehavior_For_Situation
    In case it is not possible to name the test with “when” or “for”, it is okay to write should_ExpectedBehaviour. The most important thing is that the name is as understandable as possible.

Rest Tests

  • Url and HttpEntity should be extracted. The variables should be named url and auth:

    String url = restHelper.toUrl(RestEndpoints.URL_ACCESS_ID)
                    + "?search-for=cn=ksc-users,cn=groups,OU=Test,O=TASKANA";
    HttpEntity<?> auth = restHelper.defaultRequest();
    
    ResponseEntity<List<AccessIdRepresentationModel>> response =
            TEMPLATE.exchange(
                url,
                HttpMethod.GET,
                auth,
                ACCESS_ID_LIST_TYPE);
  • When testing our REST Service, we always use an ObjectMapper instance to convert an Object to a JSON representation. We NEVER create JSON Strings manually.

  • No labels