TestNG and Spring 3

前端 未结 5 731
被撕碎了的回忆
被撕碎了的回忆 2021-01-05 16:27

What is the best practice way to do unit testing with Spring? I assume the combination TestNG & jmockit with Spring 3 isn\'t bad, so that\'s what I\'m doing right now, b

相关标签:
5条回答
  • 2021-01-05 17:13

    You might want to try hibernate-annotations-3.5.0-Beta-1 as this aligns with hibernate-core-3.5.0-Beta-1.

    I still get the java.lang.IncompatibleClassChangeError sometimes, as I'm trying to use hibernate search which is using the "old" annotations.

    Also, not sure if you are running JBoss, but if you are you'll get this error with core 3.5.0.

    0 讨论(0)
  • 2021-01-05 17:14

    Your test ckass needs to extend AbstractTestNGSpringContextTests. Or if your code is testing database acces another useful class to extend is AbstractTransactionalTestNGSpringContextTests.

    0 讨论(0)
  • 2021-01-05 17:20

    Consult the chapter on TestNG in the Spring documentation:

    • for Spring 2.5.
    • for Spring 3.0
    0 讨论(0)
  • 2021-01-05 17:26

    Now the problem doesn't seem to be related to any of Spring or TestNG. The key part is:

     java.lang.IncompatibleClassChangeError: class org.hibernate.cfg.ExtendedMappings has interface org.hibernate.cfg.Mappings as super class
    

    Are you sure your CLASSPATH is OK? I.e. you have compatible version of Hibernate modules and no repetitions there?

    What if you create a simple TestNG test that does the following:

    Class.forName("org.hibernate.cfg.ExtendedMappings");
    

    ?

    0 讨论(0)
  • 2021-01-05 17:30

    For me this problem was caused because I had different hibernate versions included myself, not because of a third party including them. A sweep of your project/poms to make sure you youserlf are only using one hibernate version is worthwhile.

    0 讨论(0)
提交回复
热议问题