Skip to main content

What test type should I choose?

Choosing the most appropriate test type is crucial for accurate test generation.

However, it is not always obvious which test type should be selected. This is because users may have different interpretations of what constitutes a unit, component, or integration test. Moreover, when working with the Spring framework, you inevitably encounter its high degree of flexibility — it offers multiple sets of annotations, each capable of producing slightly different behaviors.

This is why we decided to introduce this guide—to help you choose the most suitable test type when working with Explyt Test.

“Same as in example tests”: to choose or not to choose?

Briefly: This is the best option if you have some tests to align with.

In detail: By choosing this test type, you are asserting that the example tests serve as the ground truth for generating new tests. In other words, you are instructing Explyt Test to create new tests that follow the same annotations (e.g., Spring-specific annotations), mocking patterns, data initialization methods, code style, naming conventions, and more.

image

If you want to retain most characteristics of the example test class but make some changes, you can specify them in the More instructions field.

Keep in mind, however, that following the example is only effective if it is truly relevant to the current test generation context.

Are my “Example tests” relevant?

Explyt Test employs sophisticated algorithms and multiple heuristics to automatically identify the most suitable example tests. However, the tool may occasionally select an irrelevant test class. In some cases, choosing a truly relevant test class may not even be possible.

For example, you might need a good example for testing a Spring Controller, but all existing test classes are written for utility classes or Spring Services. As is well known, testing Services and Controllers requires very different approaches.

When Explyt Test lacks confidence in its choice of example tests, it displays the warning that alerts you about potential issues with the selected example. This makes it especially important to manually review the chosen example tests and adjust them if necessary. Even if no warning is shown, a manual check is still recommended to ensure optimal results.

image

What if I do not have suitable example tests?

Explyt Test can still assist you with test generation. However, you are now required to select a template for the test class. Selecting an appropriate template is most crucial in Spring projects.

image

Choosing the most suitable template is not always straightforward and may require some experimentation. That said, here is some advice we’d like to offer to help guide your selection:

Testing Spring Controllers:

  • Select Component tests if you prefer to test the web layer only.
  • If you intend to use @SpringBootTest, @ContextConfiguration, or other annotations that define another scope of the Spring context, choose Integration tests instead.

Testing Spring Services:

  • Choose Unit tests if you want to avoid any autowiring and generate Spring-independent tests.
  • If you wish to autowire the Service bean under test, opt for Integration tests.

Testing Spring Repositories:

  • Choose Repository tests to generate repository layer tests like @DataJpaTest.

Testing other classes:

  • Choose Unit tests to generate Spring-independent tests.
  • Choose Integration tests if context initialization is needed.

Please note that it is important to specify any additional requirements for the generated tests in the More instructions field or in the project-level persistent instructions.