Skip to content

Rerun Spring integration tests after minimization with full context reset between tests #2574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

IlyaMuravjov
Copy link
Collaborator

@IlyaMuravjov IlyaMuravjov commented Sep 1, 2023

Description

When generating integration tests we only partially reset context in between executions to save time. For example, entity id generators do not get reset. It may lead to non-reproduceable results if IDs leak to the output of the method under test.

To cope with that, we rerun all executions that are left after minimization, fully resetting Spring context between executions.

How to test

Manual tests

Generate integration tests for OrderController.getOrderById() from spring-boot-testing project, there should be test like this (with "id":1 in the expected part).

public void testGetOrderById() throws Exception {
    UriComponentsBuilder uriComponentsBuilder = fromPath("/api/orders/{id}");
    Map uriVariables = new HashMap();
    Order order = new Order();
    entityManager.persist(order);
    entityManager.flush();
    Long long1 = ((Long) getFieldValue(order, "com.rest.order.models.Order", "id"));
    uriVariables.put("id", long1);
    UriComponentsBuilder uriComponentsBuilder1 = uriComponentsBuilder.uriVariables(uriVariables);
    String urlTemplate = uriComponentsBuilder1.toUriString();
    Object[] uriVariables1 = {};
    MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(urlTemplate, uriVariables1);

    ResultActions actual = mockMvc.perform(mockHttpServletRequestBuilder);

    actual.andDo(print());
    actual.andExpect((status()).is(200));
    actual.andExpect((content()).string("{\"id\":1,\"buyer\":null,\"price\":null,\"qty\":0}"));
}

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@IlyaMuravjov IlyaMuravjov added ctg-enhancement New feature, improvement or change request comp-instrumented-process Issue is related to Instrumented process comp-spring Issue is related to Spring projects support labels Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-instrumented-process Issue is related to Instrumented process comp-spring Issue is related to Spring projects support ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants