PowerMock测试 mock hbase连接
来源:互联网 发布:盛讯珠宝软件 编辑:程序博客网 时间:2024/04/30 13:52
junit测试中,当无法连接hbase集群,使用PowerMock测试 mock hbase连接,mock类如下:
/** * QueryCanTask Tester. * * @author <Authors name> * @since 12/18/2017 * @version 1.0 */ @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class) //委派给SpringJUnit4ClassRunner @PowerMockIgnore("javax.management.*") @PrepareForTest({ HBaseConfiguration.class, ConnectionFactory.class, Configuration.class, Table.class, ResultScanner.class}) //@SuppressStaticInitializationFor("com.xxxx")//阻止静态代码块运行@ContextConfiguration(locations = { "classpath:applicationContext/*.xml" })public class QueryCanTaskTest{ private Configuration configuration = PowerMockito.mock(Configuration.class); private Connection connection = PowerMockito.mock(Connection.class); private Table table = PowerMockito.mock(Table.class); @Before public void before() throws Exception { //初始化静态变量 new SystemCfgConstants(); PowerMockito.when(HBaseConfiguration.create()).thenReturn(configuration); PowerMockito.when(ConnectionFactory.createConnection(configuration)).thenReturn(connection); PowerMockito.when(Connections.getTable(TableInfo.TABLE)).thenReturn(table); PowerMockito.when(Connections.getTable(RawDataTable.tableName)).thenReturn(table); PowerMockito.when(table.getScanner(scan)).thenReturn(yourest); } @After public void after() throws Exception { } /** * * Method: * */ @Test public void testQueryList() throws Exception { //TODO test }}
在hbase-site.xml添加如下配置,跳过版本检查
<property> <name>hbase.defaults.for.version.skip</name> <value>true</value> <description> Set to true to skip the 'hbase.defaults.for.version' check. Setting this to true can be useful in contexts other than the other side of a maven generation; i.e. running in an ide. You'll want to set this boolean to true to avoid seeing the RuntimException complaint: "hbase-default.xml file seems to be for and old version of HBase (0.92.1), this version is X.X.X-SNAPSHOT" </description> </property>
阅读全文
0 0
- PowerMock测试 mock hbase连接
- Java单元测试之模拟利器-使用PowerMock进行Mock测试
- PowerMock - mock静态方法
- powermock mockito mock static
- 一个牛x的mock框架--Powermock
- powermock replace or mock parent's method
- 使用PowerMock来Mock静态函数
- 一个牛x的mock框架--Powermock
- 一个牛x的mock框架--Powermock
- 一个牛x的mock框架--Powermock
- 一个牛x的mock框架--Powermock
- 四.Android单元测试 PowerMock mock静态方法
- 用powermock mock Dao Http请求 log4j
- powermock mock 静态类,静态属性
- PowerMock测试小例
- java测试--powerMock
- mock 测试
- mock测试
- JAVA中的数据类型
- idea中deployment点击加号没有出现artifact
- 【C++ STL学习之三】容器deque深入学习
- ssm项目升级 struts2.3.32升级到2.5.13
- 【备忘】大数据学习从入门到精通学习路线视频教程 100G
- PowerMock测试 mock hbase连接
- python操作redis操作方法实例
- tablelayout的使用
- 怎么跳出MySQL的10个大坑
- RocketMQ原理解析-producer 1.启动流程
- Java中(Integer)127 == (Integer)127和(Integer)129 == (Integer)129表达式结果差异分析
- 一个简单的网络判断的方法
- 设计模式-建造者模式
- 记录 Annotation processing is not supported for module cycles.