简体   繁体   English

声纳上的java.lang.ClassCastException

[英]java.lang.ClassCastException on Sonar

Recently I've been assigned to examine Java code coverage using Sonar with Maven. 最近,我被派去使用Sonar和Maven检查Java代码覆盖率。 I run mvn sonar:sonar and the build comes out just fine, plus I can see the result from the dashboard. 我运行mvn sonar:sonar ,构建就很好了,而且我可以从仪表板看到结果。

However, the test cases come out as errors, which does not happen at all if I run it normally. 但是,测试用例是作为错误出现的,如果我正常运行它根本不会发生。 Here is the error stack trace: 这是错误堆栈跟踪:

$Proxy11 cannot be cast to com.epsilon.agility.message.dao.MessageDAO
java.lang.ClassCastException: $Proxy11 cannot be cast to                    com.epsilon.agility.message.dao.MessageDAO
at  com.epsilon.agility.message.utils.MessageDBAdaptorService.getMessageDAO(MessageDBAdaptorSer vice.java:32)
at com.epsilon.agility.message.facade.MessageClassificationFacadeImpl.initilaizeDAOs(MessageClassificationFacadeImpl.java:91)
at com.epsilon.agility.message.facade.MessageClassificationFacadeImpl.<init>(MessageClassificationFacadeImpl.java:86)
at com.epsilon.agility.message.dao.test.TestMessageClassificationFacadeImpl.setUp(TestMessageClassificationFacadeImpl.java:85)
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.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:49)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:36)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
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.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

Here is the method involved in the error: 这是错误所涉及的方法:

@BeforeClass
@Transactional(propagation = Propagation.REQUIRED, timeout = 10)
public static void setUp() throws IOException {
    conn = TestDBUtils.getDBConnection();

    MessageDBAdaptorService.init(conn);

    msgclassificationFacade = new MessageClassificationFacadeImpl(conn);

    messageDAO = MessageDBAdaptorService.getMessageDAO();
    messageAssetDAO = MessageDBAdaptorService.getMessageAssetDAO();
    channelDAO = MessageDBAdaptorService.getChannelDAO();
    folderItemDAO = MessageDBAdaptorService.getFolderItemDAO();
    folderDAO = MessageDBAdaptorService.getFolderDAO();


    Assert.assertNotNull(messageDAO);
    Assert.assertNotNull(messageAssetDAO);
    Assert.assertNotNull(channelDAO);
    Assert.assertNotNull(folderItemDAO);
    Assert.assertNotNull(folderDAO);

}

I've searched the solutions online but it seems that there is no similar solution for Sonar. 我已经在线搜索了解决方案,但似乎没有类似的Sonar解决方案。 I suspect that the problem might come from Sonar's different approach for test cases since the test cases run fine on normal basis. 我怀疑问题可能是由于Sonar的测试用例不同,因为测试用例在正常情况下运行良好。

I will post more code and information if the above are not enough. 如果以上内容还不够,我将发布更多代码和信息。 Thanks for any help. 谢谢你的帮助。

It doesn't seem to be a Sonar problem. 似乎不是声纳问题。 From the stack trace I assume that maven surefire plugin can't execute a particular test. 从堆栈跟踪中,我认为Maven surefire插件无法执行特定测试。 If I were you I'd the following. 如果我是你,我会以下。 - Verify that you custom build and Sonar are using the same maven surefire plugin version and have the same configuration. -验证您的自定义版本和Sonar是否使用相同的maven surefire插件版本并具有相同的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM