...
Tests should not be public
Instance variables should have no modifiers
Constants have to be
private static final
The test API should only be used for setting up the test case. Tested behavior should be implemented using the API of TASKANA.
Example: If creating a Task is the test case, then use
Code Block Task task = taskService.newTask(defaultWorkbasketSummary.getId()); task.setClassificationKey(defaultClassificationSummary.getKey()); task.setPrimaryObjRef(defaultObjectReference); task.setManualPriority(123); Task result = taskService.createTask(task);
instead of
Code Block Task task = TaskBuilder.newTask() .classificationSummary(defaultClassificationSummary) .workbasketSummary(defaultWorkbasketSummary) .primaryObjRef(defaultObjectReference) .manualPriority(123).buildAndStore(taskService);
If possible, getting entities from the database should be avoided by using return values.
Example:
Code Block Task task = createDefaultTask().manualPriority(123).buildAndStore(taskService); task.setManualPriority(42); Task result = taskService.updateTask(task);
instead of
Code Block Task task = createDefaultTask().manualPriority(123).buildAndStore(taskService); task.setManualPriority(42); taskService.updateTask(task); Task result = taskService.getTask(task.getId());
If tests throw any exception, they must throw
Exception.class
onlyTestclass 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.
Code Block assertThat(events) .extracting(WorkbasketHistoryEvent::getEventType) .containsExactly(WorkbasketHistoryEventType.DISTRIBUTION_TARGET_ADDED.getName());
instead of
Code Block type = events.get(0).getEventType(); assertThat(type).isEqualTo(WorkbasketHistoryEventType.DISTRIBUTION_TARGET_ADDED.getName());
...