ppalaga commented on code in PR #3847:
URL: https://github.com/apache/camel-quarkus/pull/3847#discussion_r920039028


##########
docs/modules/ROOT/pages/user-guide/testing.adoc:
##########
@@ -226,3 +226,27 @@ class MyTest {
 ----
 
 More examples of WireMock usage can be found in the Camel Quarkus integration 
test source tree such as 
https://github.com/apache/camel-quarkus/tree/main/integration-tests/geocoder[Geocoder].
+
+== `CamelTestSupport` style of testing
+
+If you used plain Camel before, you may know 
https://camel.apache.org/components/latest/others/test-junit5.html[CamelTestSupport]
 already.
+Unfortunately the Camel variant won't work on Quarkus and so we prepared a 
replacement called `CamelQuarkusTestSupport`, which can be used in JVM mode.
+
+There are several limitations:
+
+* Test has to be annotated by `@QuarkusTest` and has to extend 
`CamelQuarkusTestSupport`.
+* Quarkus runs tests in a custom classloader which JUnit is not aware of (see 
the 
https://quarkus.io/guides/getting-started-testing#applying-interceptors-to-tests[documentation]).
 If JUnit's callback (i.e. 
`org.junit.jupiter.api.extension.BeforeEachCallback`) is used, it may not work 
as expected. Use the quarkus callbacks instead (see the 
https://quarkus.io/guides/getting-started-testing#enrichment-via-quarkustestcallback[documentation])
 or use annotations like `@org.junit.jupiter.api.BeforeEach`.
+* Camel Quarkus lifecycle does not allow to start/stop Camel context. Context 
is started before execution of the first test and closed after the finish of 
the last one. Test has to be written with consideration with this limitation. 
If it is not possible to write a test with such limitation, `@TestProfile` has 
to be used. Test profile forces quarkus to restart its engine, therefore it 
creates a new Camel context (see the 
https://quarkus.io/guides/getting-started-testing#testing_different_profiles/[documentation]
 about this feature).

Review Comment:
   ```suggestion
   * Camel Quarkus does not support stopping and re-starting the same 
`CamelContext` instance within the life cycle of a single application. You will 
be able to call `CamelContext.stop()`, but `CamelContext.start()` won't work.
   * Starting and stopping `CamelContext` in Camel Quarkus is generally bound 
to starting and stopping the application and this holds also when testing. 
   * Starting and stopping the application under test (and thus also 
`CamelContext`) is under full control of Quarkus JUnit Extension. It prefers 
keeping the application up and running unless it is told to do otherwise.
   * Hence normally the application under test is started only once for all 
test classes of the given Maven/Gradle module.
   * To force Quarkus JUnit Extension to restart the application (and thus also 
`CamelContext`) for a given test class, you need to assign a unique 
`@io.quarkus.test.junit.TestProfile` to that class. Check the 
https://quarkus.io/guides/getting-started-testing#testing_different_profiles[Quarkus
 documentation] how you can do that. (Note that 
`https://quarkus.io/guides/getting-started-testing#quarkus-test-resource[@io.quarkus.test.common.QuarkusTestResource]`
 has a similar effect.)
   ```



##########
docs/modules/ROOT/pages/user-guide/testing.adoc:
##########
@@ -226,3 +226,27 @@ class MyTest {
 ----
 
 More examples of WireMock usage can be found in the Camel Quarkus integration 
test source tree such as 
https://github.com/apache/camel-quarkus/tree/main/integration-tests/geocoder[Geocoder].
+
+== `CamelTestSupport` style of testing
+
+If you used plain Camel before, you may know 
https://camel.apache.org/components/latest/others/test-junit5.html[CamelTestSupport]
 already.
+Unfortunately the Camel variant won't work on Quarkus and so we prepared a 
replacement called `CamelQuarkusTestSupport`, which can be used in JVM mode.
+
+There are several limitations:
+
+* Test has to be annotated by `@QuarkusTest` and has to extend 
`CamelQuarkusTestSupport`.

Review Comment:
   ```suggestion
   * The test class has to be annotated with 
`@io.quarkus.test.junit.QuarkusTest` and has to extend 
`org.apache.camel.quarkus.test.CamelQuarkusTestSupport`.
   ```



##########
docs/modules/ROOT/pages/user-guide/testing.adoc:
##########
@@ -226,3 +226,27 @@ class MyTest {
 ----
 
 More examples of WireMock usage can be found in the Camel Quarkus integration 
test source tree such as 
https://github.com/apache/camel-quarkus/tree/main/integration-tests/geocoder[Geocoder].
+
+== `CamelTestSupport` style of testing
+
+If you used plain Camel before, you may know 
https://camel.apache.org/components/latest/others/test-junit5.html[CamelTestSupport]
 already.
+Unfortunately the Camel variant won't work on Quarkus and so we prepared a 
replacement called `CamelQuarkusTestSupport`, which can be used in JVM mode.
+
+There are several limitations:
+
+* Test has to be annotated by `@QuarkusTest` and has to extend 
`CamelQuarkusTestSupport`.
+* Quarkus runs tests in a custom classloader which JUnit is not aware of (see 
the 
https://quarkus.io/guides/getting-started-testing#applying-interceptors-to-tests[documentation]).
 If JUnit's callback (i.e. 
`org.junit.jupiter.api.extension.BeforeEachCallback`) is used, it may not work 
as expected. Use the quarkus callbacks instead (see the 
https://quarkus.io/guides/getting-started-testing#enrichment-via-quarkustestcallback[documentation])
 or use annotations like `@org.junit.jupiter.api.BeforeEach`.
+* Camel Quarkus lifecycle does not allow to start/stop Camel context. Context 
is started before execution of the first test and closed after the finish of 
the last one. Test has to be written with consideration with this limitation. 
If it is not possible to write a test with such limitation, `@TestProfile` has 
to be used. Test profile forces quarkus to restart its engine, therefore it 
creates a new Camel context (see the 
https://quarkus.io/guides/getting-started-testing#testing_different_profiles/[documentation]
 about this feature).
+The `CamelQuarkusTestSupport` implements `QuarkusTestProfile`, therefore the 
test class could be used as a value for `@TestProfile`.
+*  Camel Quarkus executes the production of beans during the build phase. 
Because all the tests are
+build together,  exclusion behavior is implemented into 
`CamelQuarkusTestSupport`. If a producer of the specific type and name is used 
in one tests, the instance will be the same for the rest of the tests.
+
+[source,java]
+----
+@QuarkusTest
+@TestProfile(SimpleTest.class) //necessary only if "newly created" context is 
required for the test (worse performance)
+public class SimpleTest extends CamelQuarkusTestSupport {
+    ...
+}
+----
+

Review Comment:
   Did we say somewhere that they need to add camel-quarkus-junit5 preferably 
in test scope to be able to use CamelQuarkusTestSupport?



##########
docs/modules/ROOT/pages/user-guide/testing.adoc:
##########
@@ -226,3 +226,27 @@ class MyTest {
 ----
 
 More examples of WireMock usage can be found in the Camel Quarkus integration 
test source tree such as 
https://github.com/apache/camel-quarkus/tree/main/integration-tests/geocoder[Geocoder].
+
+== `CamelTestSupport` style of testing
+
+If you used plain Camel before, you may know 
https://camel.apache.org/components/latest/others/test-junit5.html[CamelTestSupport]
 already.
+Unfortunately the Camel variant won't work on Quarkus and so we prepared a 
replacement called `CamelQuarkusTestSupport`, which can be used in JVM mode.
+
+There are several limitations:
+
+* Test has to be annotated by `@QuarkusTest` and has to extend 
`CamelQuarkusTestSupport`.
+* Quarkus runs tests in a custom classloader which JUnit is not aware of (see 
the 
https://quarkus.io/guides/getting-started-testing#applying-interceptors-to-tests[documentation]).
 If JUnit's callback (i.e. 
`org.junit.jupiter.api.extension.BeforeEachCallback`) is used, it may not work 
as expected. Use the quarkus callbacks instead (see the 
https://quarkus.io/guides/getting-started-testing#enrichment-via-quarkustestcallback[documentation])
 or use annotations like `@org.junit.jupiter.api.BeforeEach`.

Review Comment:
   Is this really relevant for end users? They are not supposed to use 
org.junit.jupiter.api.extension.BeforeEachCallback. That one is for JUnit 5 
extension developers, no?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to