Powermock 和 Spring 在测试中注入 EntityManager 时引起转换异常
当尝试使用PowerMockRule技术将Spring测试运行程序和PowerMock运行程序组合在一起时,每当我尝试使用JPA中的注释注入注释时,我都会从Thoughtworks XStream库中获得异常。不使用 .在测试开始时,我还忽略了PowerMockLoader中的所有软件包。我尝试了各种值,因为这通常可以解决我在PowerMock上遇到的问题,但是,即使完全忽略每个包,此错误仍然会发生。EntityManager
PersistenceContext
PowerMockRule
@PowerMockIgnore
@PowerMockIgnore("*")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/test-configuration.xml")
public class SpringAndPowerMockTest {
@Rule
public PowerMockRule rule = new PowerMockRule();
@PersistenceContext
private EntityManager manager;
@Test
public void test() {
}
}
例外情况如下 -- 在 pastebin 上指向完整回溯的链接,回溯跟踪超出了问题长度的限制):
相关持久性单元:
<persistence-unit name="inMemory">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.driver_class" value="org.h2.Driver" />
<property name="hibernate.connection.url" value="jdbc:h2:mem:InMemoryUnitTests;MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
</properties>
</persistence-unit>
Maven dependencies:
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-classloading-xstream</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>
</dependencies>
使用弹簧进行测试。请注意,我还使用弹簧测试版本进行了测试,该版本确实解决了Spring / Powermock组合的其他一些错误,但不是这个错误。3.2.3.RELEASE
3.0.5.RELEASE