PoweMock統合Spring-testテスト静的方法無効バイトコード検証-noverify-XX:-UseSplity Verifer
14365 ワード
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:springmvc-servlet-test.xml", "classpath:application-context-datasource-test.xml",
"classpath:springbeans/mq-beans-test.xml","classpath:springbeans/ws-beans-test.xml","classpath:springbeans/task-beans-test.xml", "classpath:springbeans/threadpool-beans-test.xml"})
public class JUnitServiceBase extends AbstractJUnit4SpringContextTests {
}
そしてテストクラスは、このクラスをそのまま引き継いで直接に私たちのスプリングフレームを走らせます.これは間違いないです.しかし、ちょっと小さい問題があります.私たちはPowerMockを模擬するにも@RunWithが必要です.この二つは同時に存在してはいけません.@RunWith(SpringJUnit 4 Class)これは高いバージョンのPowemokの中で、いくつかの改善をしたのもこの問題を解決したいのです.まず、私たちのパワーロックの配置を見てみましょう.<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.5</version>
<scope>test</scope>
</dependency>
公式文書の例では、この問題を解決する方法が見られます.テストの時、テストクラスに次のような注釈をつけて、問題を解決することができます.@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
// RunWith ~ !
@ContextConfiguration("classpath:/example-context.xml")
@PrepareForTest(IdGenerator.class)
http://blog.csdn.net/jackiehff/article/details/14000779 ここで上のリンクは私達の基本的な使用説明です.PoweMockについて. java.lang.VerifyError: Inconsistent stackmap frames at branch target 38 Exception Details: Locatio
http://stackoverflow.com/questions/15122890/java-lang-verifyerror-expecting-a-stackmap-frame-at-branch-target-jdk-1-7 これは解決案Java 7 introduced a stricter verification and changed the clast format a bit–to contain a stack map,used to verify that code is corect.The exception you seeです.means that some method doesn’t have a valid stack map.Java version or bytecode instruction could both be to blame.Usually this means that a librarythat the appration uss,genersavalid bytecode that doesn’t pass the stricter verification.Sonobuting the
As workound you can add-noverify to the JVM argments in order to disable verification.In Java 7 it was also possible to use-XX:-UseSplityVer to use the less strit verification method,buthmotion 8
解決方法として、noverifyのJVMパラメータを追加して検証を無効にすることができます.java 7ではさらにXX:-usesplitverifeierを使用してより厳しい検証方法を使用することができますが、選択はjava 8で除去されます.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd" default-lazy-init="true">
<!-- -->
<context:component-scan base-package="com.hikvision.cms.pms.**.action" />
<context:component-scan base-package="com.hikvision.cms.pms.**.service" />
<context:component-scan base-package="com.hikvision.cms.pms.**.dao" />
<context:component-scan base-package="com.hikvision.cms.pms.**.api" />
<!-- Tree -->
<context:component-scan base-package="com.hikvision.cms.pms.common.tree" />
<!-- ref -->
<context:component-scan base-package="com.hikvision.cms.pms.ref" />
<!-- , , spring mvc -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- <bean id="sysLogAspect" class="com.hikvision.cms.module.baseapp.common.service.SysLogAspect"/> -->
<!-- springmvc json -->
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="com.hikvision.cms.common.web.bind.ExtServletModelAttributeMethodProcessor"/>
<bean class="com.hikvision.cms.common.web.bind.ExtRequestBodyArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
<!-- -->
<mvc:interceptors>
<!-- <bean class="com.hikvision.cms.common.interceptor.DBLogInterceptor" /> -->
<bean class="com.hikvision.cms.common.web.interceptor.HttpServletResponseInterceptor" />
<bean class="com.hikvision.cms.common.web.interceptor.ModelAndViewAttributesAutoSetInterceptor" />
</mvc:interceptors>
<!-- -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/views/"/>
<property name="suffix" value=".jsp" />
</bean>
<!-- -->
<bean id="exceptionResolver" class="com.hikvision.cms.common.web.resolver.CustomSimpleMappingExceptionResolver" />
<!-- SpringMVC , MultipartResolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<!-- , -->
<!-- <property name="maxUploadSize" value="102400000" /> -->
</bean>
</beans>