@Test
public void testGetOnlyNewPartitions() throws Exception {
setUp();
new Expectations(){
HiveUtil hiveUtil;
{
HiveUtil.getInstance(); returns(hiveUtil);
hiveUtil.getAllpartitions(oldTable); returns(oldPartitions);
hiveUtil.getAllpartitions(newTable); returns(newPartitions);
}
};
PartitionFilter partitionFilter = new PartitionFilter(oldTable, newTable, HiveUtil.getInstance());
}
我正在对使用单例类 HiveUtil 的类 PartitionFilter 进行单元测试。
我的测试用例在运行时出现错误“java.lang.IllegalStateException:用于记录期望的无效上下文”。关于为什么会发生这种情况的任何解释?
这是我的 pom.xml 的相关部分:
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
我试图将 jmockit 依赖项放在 pom 中的 junit 依赖项之前。那没有用。
更多研究表明我没有在课程开始时使用 @RunWith(JMockit.class) 注释。但是,当我尝试使用它时,出现错误“无法将类解析为类型”。我做了所有相关的进口。
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.*;
import mockit.*;
import mockit.integration.junit4.*;
import junit.framework.TestCase;
我究竟做错了什么?