What is the difference between @CamelSpringTest and @CamelSpringBootTest?

Viewed 1160

I am just starting a projects that combines Spring Boot and Apache Camel (what seems a very nice combination).

In regards of testing with JUnit 5 Google brings up this page. It suggests to use @CamelSpringTest if you want to have both the annotations from Spring and Camel (what i want).

At the and of the page there are suggestion for JUnit 4 Test migration that suggests:

Usage of @RunWith(CamelSpringRunner.class) should be replaced with @CamelSpringTest ... Usage of @RunWith(CamelSpringBootRunner.class) should be replaced with @CamelSpringBootTest

My question is for new project/ tests: What is the difference of both in regards of usage.
There is of course difference in code but i don't have a clue for what reason:

CamelSpringTest:

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@ExtendWith(SpringExtension.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@TestExecutionListeners(
                        value = {
                                CamelSpringTestContextLoaderTestExecutionListener.class,
                                StopWatchTestExecutionListener.class
                        },
                        mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public @interface CamelSpringTest {

}

CamelSpringBootTest

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE })
@ExtendWith(SpringExtension.class)
@TestExecutionListeners(
                        value = {
                                CamelSpringTestContextLoaderTestExecutionListener.class,
                                CamelSpringBootExecutionListener.class,
                                StopWatchTestExecutionListener.class
                        },
                        mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
public @interface CamelSpringBootTest {

}
1 Answers

The difference is quite simple: is the test running in a SpringBoot project or not?

Camel can be used in a pure Spring project (without Boot). In such a project you can either extend CamelSpringTestSupport to write Tests or you can use @CamelSpringTest annotation. The tests are then started and initialized for this environment.

When you use Camel in a SpringBoot project, Camel can leverage this environment with auto-configuration etc. Therefore you have to use another annotation, @CamelSpringBootTest, to write tests. See here for an example.

So the two annotations are just "activators" for two different Camel test facilities for different project types. And these are just the Spring facilities. See this page for even more Camel test facilities.

This is also the source of many confusions around Camel testing. There are so much test variations, Spring, SpringBoot, JUnit 4, JUnit 5 etc. it is really hard to know what annotations are needed for what combinations of testing setup.

Related