我为HBase编写了一个本地集成测试,该测试运行在HBaseTestingUtility上,使用HBaseTestingUtility设置HBase的本地实例:
public class HBaseTestServer extends ExternalResource {
private HBaseTestingUtility hbaseUtility;
@Override
protected void before() throws Exception {
System.setProperty("test.build.data.basedirectory", "C:/Temp/hbase");
this.hbaseUtility = new HBaseTestingUtility();
this.hbaseUtility.startMiniCluster();
}
...如果我单独运行集成测试类,它就能正常工作。但是,这个类在另一个测试类之后运行,它使用PowerMock模拟HBase:
@RunWith(PowerMockRunner.class)
@PrepareForTest({HBaseAdapter.class, Connection.class, ConnectionFactory.class})
public class HBaseAdapterTest {
...如果我在我的项目上运行所有测试,那么PowerMock HBaseAdapterTest就会首先运行,而我的集成测试也会失败:
java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
at org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Native Method)
at org.apache.hadoop.io.nativeio.NativeIO$Windows.access(NativeIO.java:606)
at org.apache.hadoop.fs.FileUtil.canWrite(FileUtil.java:977)这里发生了什么事?在我的集成测试运行之前,我想我需要清除所有的PowerMock模拟,但是我在网上找不到任何有用的东西。
对于任何对依赖感兴趣的人来说:
compile 'org.apache.hadoop:hadoop-client:2.8.1'
compile 'org.apache.hbase:hbase-client:1.1.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.8.0'
testCompile 'org.powermock:powermock-api-mockito2:1.7.0RC2'
testCompile 'org.powermock:powermock-module-junit4:1.7.0'
testCompile 'org.powermock:powermock-core:1.7.0'
testCompile 'org.powermock:powermock-module-junit4-rule:1.7.0'发布于 2018-04-09 11:41:45
根据Tom的评论,在不同的实例中运行测试已经解决了我的问题。在build.gradle中,我添加了:
test {
forkEvery 1
}https://stackoverflow.com/questions/49730238
复制相似问题