Page 1 of 1

Code coverage

Posted: Wed Oct 30, 2013 4:54 am
by listaka
Hi all,

I'm trying to hook up Broadleaf(main project, not the Demo Site) to Sonar in order to generate some quality metrics.

I'm facing a problem with the "integration" module(which is the more interesting one), sounds like an AOP problem but I didn't manage to solve it.

Here is the maven goals i'm calling :
mvn clean install sonar:sonar -Dmaven.test.failure.ignore=true


And Here is the stackTrace :

Code: Select all

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.broadleafcommerce.core.order.service.legacy.LegacyOrderTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'blOrderService' must be of type [org.broadleafcommerce.core.order.service.legacy.LegacyCartService], but was actually of type [sun.proxy.$Proxy129]
   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1122)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:379)
   at org.broadleafcommerce.test.MergeDependencyInjectionTestExecutionListener.injectDependencies(MergeDependencyInjectionTestExecutionListener.java:32)
   at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
   at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
   at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:130)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:607)
   at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:417)
   at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:154)
   at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:88)
   at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:167)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
   at org.testng.TestRunner.runWorkers(TestRunner.java:759)
   at org.testng.TestRunner.privateRun(TestRunner.java:592)
   at org.testng.TestRunner.run(TestRunner.java:486)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
   at org.testng.SuiteRunner.run(SuiteRunner.java:204)
   at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
   at org.testng.TestNG.run(TestNG.java:751)
   at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:70)
   at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:158)
   at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:98)
   at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:111)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:601)
   at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
   at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
   at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
   at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
   at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'blOrderService' must be of type [org.broadleafcommerce.core.order.service.legacy.LegacyCartService], but was actually of type [sun.proxy.$Proxy129]
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:361)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)
   at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
   at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
   at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
   ... 39 more
Tests run: 406, Failures: 1, Errors: 0, Skipped: 382, Time elapsed: 30.96 sec <<< FAILURE!

Results :

Failed tests:   springTestContextPrepareTestInstance(org.broadleafcommerce.core.order.service.legacy.LegacyOrderTest): Error creating bean with name 'org.broadleafcommerce.core.order.service.legacy.LegacyOrderTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'blOrderService' must be of type [org.broadleafcommerce.core.order.service.legacy.LegacyCartService], but was actually of type [sun.proxy.$Proxy129]

Tests run: 406, Failures: 1, Errors: 0, Skipped: 382


I already tried to add
<aop:config proxy-target-class="true">

everywhere but the only it changes is the error :

Code: Select all

Failed tests:   springTestContextPrepareTestInstance(org.broadleafcommerce.core.order.service.legacy.LegacyOrderTest): Error creating bean with name 'org.broadleafcommerce.core.order.service.legacy.LegacyOrderTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'blOrderService' must be of type [org.broadleafcommerce.core.order.service.legacy.LegacyCartService], but was actually of type [org.broadleafcommerce.core.order.service.OrderServiceImpl$$EnhancerByCGLIB$$5cb437d1]


Do you have any idea on how to solve this ?

Do you use another tool to generate your code coverage, like cobertura or jacoco ? If so, is it possible to have the results ?

I'm not particularly picky about quality metrics but the code coverage is a requirement from the university (This is for an academic project).

Thanks in advance !

Re: Code coverage

Posted: Mon Dec 02, 2013 1:52 pm
by jefffischer
We are phasing out the legacy cart tests, as they mostly point to unused code in our codebase. However, I have addressed this issue in a recent commit to the 3.0.x support branch (see https://github.com/BroadleafCommerce/Br ... issues/571). Please note, if you decide to get this fix and execute the legacy tests, you will currently have 4 failed tests. I'm not sure if this is something you need to avoid, or if it doesn't matter. Nonetheless, it would be my suggestion to leave the <skipTests> element set to true for the "default-test" execution, which would leave you with the "non-legacy-test" execution still working.

Re: Code coverage

Posted: Sun Dec 08, 2013 8:48 pm
by listaka
Hello,

I'll try it out. Failed tests are not that important, all I want is some metrics.

Thank you for the fix and the reply !