It make sense that create a new camel context per test take more time if you 
just restart the camel context.
As you are not change the camel route setting differently for each test, so it 
should be OK for you just stop and start the camel context before and after the 
test.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) 
(English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Monday, November 11, 2013 at 4:41 AM, PJ Walstroem wrote:

> hello,
> I was wondering about the use of the DirtiesContext-annotation at the
> class-level. According to http://camel.apache.org/spring-testing.html, it
> "forces Spring Testing to automatically reload the CamelContext after each
> test method - this ensures that the tests don't clash with each other".
> Reloading the CamelContext takes a while, and I find that my tests are time
> consuming when using this annotation (option 1 below).  
>  
> I find that my test run much faster with option 2 below, but I am not sure
> about the side-effects. All tests send messages to the same endpoint which
> is mockEndpointsAndSkip in the adviceWith, but I find when I stop and start
> the context, the tests do seem to run isolated. Any thoughts?
>  
>  
> Option 1, DirtiesContext:
> @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @UseAdviceWith
> public final class RouteBuilderTest {...
>  
> @Before
> public void setupRouteDefinitionAdviceHttp() throws Exception {
> context.getRouteDefinition(Route.SOLRIZE.name 
> (http://Route.SOLRIZE.name)()).adviceWith(context,
> new AdviceWithRouteBuilder() {
> @Override
> void configure() throws Exception {
> mockEndpointsAndSkip("http4:localhost:5432");
> }
> })
> context.start();
> }
>  
> Option 2, just restart the context:
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @UseAdviceWith
> public final class RouteBuilderTest {...
>  
> @Before
> public void setupRouteDefinitionAdviceHttp() throws Exception {
> context.getRouteDefinition(Route.SOLRIZE.name 
> (http://Route.SOLRIZE.name)()).adviceWith(context,
> new AdviceWithRouteBuilder() {
> @Override
> void configure() throws Exception {
> mockEndpointsAndSkip("http4:localhost:5432");
> }
> })
> context.start();
> }
>  
> @After
> public void stopContext() {
> context.stop();
> }
>  
>  
>  
>  
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/DirtiesContext-vs-just-restarting-context-tp5742981.html
> Sent from the Camel - Users mailing list archive at Nabble.com 
> (http://Nabble.com).



Reply via email to