国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

Jmockdata 使用介紹(再也不用苦逼的造測試數(shù)據(jù)了)

2019-11-10 17:20:49
字體:
供稿:網(wǎng)友

Jmockdata

Jmockdta是一款實現(xiàn)模擬java類型或?qū)ο蟮膶嵗㈦S機初始化對象的數(shù)據(jù)的工具框架。單元測試的利器。The plug-in of Jmockdata what through random algorithm mock java data.Jmockdata插件通過隨機算法模擬Java數(shù)據(jù).

具體介紹和用法可以參考如下:

模擬數(shù)據(jù)入口方法 JMockData.mock(JmockDataWrapper)被模擬數(shù)據(jù)必須繼承JmockDataWrapper經(jīng)過它的包裝被模擬的數(shù)據(jù)最好是plain bean,只提供getter,setter,has,is方法的才可以被模擬

框架默認(rèn)實現(xiàn)了40個元數(shù)據(jù)類型的數(shù)據(jù)模擬器包括:

short.class,Short.class,short[].class,Short[].class, int.class,Integer.class,int[].class,Integer[].class, long.class,Long.class,long[].class,Long[].class, float.class,Float.class,float[].class,Float[].class, double.class,Double.class,double[].class,Double[].class, boolean.class,Boolean.class,boolean[].class,Boolean[].class, char.class,Character.class,char[].class,Character[].class, String.class,String[].class, BigDecimal.class,BigDecimal[].class, BigInteger.class,BigInteger[].class, Date.class,Date[].class

通過對以上基本元數(shù)據(jù)類型的模擬實現(xiàn),能夠進(jìn)一步實現(xiàn)BEAN,LIST,SET,ARRAY等結(jié)構(gòu)的模擬。

可以通過JmockDataContext 獲取模擬過程的所有上下文信息,甚至可以打印整個模擬類型樹 可以通過JMockDataManager 注冊模擬數(shù)據(jù)類型,重寫模擬數(shù)據(jù)算法,注冊模擬數(shù)據(jù)類攔截器等可以通過實現(xiàn)MockData來實現(xiàn)一個模擬數(shù)據(jù)類型可以通過實現(xiàn)JmockDataTemplate,或者繼承JmockDataTemplateDefault來重寫模擬數(shù)據(jù)算法可以通過實現(xiàn)JmockDataInterceptor來實現(xiàn)一個攔截器具體示例實踐請參考https://github.com/jsonzou/jmockdata-demo有問題或者對本框架有新的想法,請聯(lián)系我, 作者:jsonzou

下載引入:Download

Jmockdata-2.0

Jar

Jmockdata-2.0

Maven

<dependency> <groupId>com.github.jsonzou</groupId> <artifactId>jmockdata</artifactId> <version>2.0</version> </dependency>

Gradle

compile group: 'com.github.jsonzou', name: 'jmockdata', version: '2.0'

Jmockdata-1.0

Jar

Jmockdata-1.0

Maven

<dependency> <groupId>com.github.jsonzou</groupId> <artifactId>jmockdata</artifactId> <version>1.0</version> </dependency>

Gradle

compile group: 'com.github.jsonzou', name: 'jmockdata', version: '1.0'

測試示例

具體示例請參考:https://github.com/jsonzou/jmockdata-demo或者下載該示例項目Please refer to the specific example:https://github.com/jsonzou/jmockdata-demo Ordownload the demo PRoject>

示例代碼片段如下:

/* * Copyright (C) 2016 Baidu, Inc. All Rights Reserved. */ package org.jsonzou.jmockdata.test; import com.alibaba.fastjson.JSON; import org.jsonzou.jmockdata.JMockData; import org.jsonzou.jmockdata.mockdata.JMockDataManager; import org.jsonzou.jmockdata.test.custommocktemplate.CustomJmockDataTemplate; import org.jsonzou.jmockdata.test.interceptor.OneJmockDataInterceptor; import org.jsonzou.jmockdata.test.registermockdatabean.MockDataStringBuffer; import org.jsonzou.jmockdata.test.wrapperbean.*; import org.junit.Test; /** * 測試 * * @author jsonzou * @version 1.0 * @since 2016/12/26 */ public class JMockDataTest { /** * 測試模擬簡單List<String> */ @Test public void mockTest_SimpleStringList() { MockDemoSimpleListStringWrapper mockData = JMockData.mock(MockDemoSimpleListStringWrapper.class); mockData.getJmockDataContext().printTree(); // 打印類型樹 print(mockData.getList()); } /** * 測試模擬任意類型的數(shù)據(jù) */ @Test public void mockTest_MockAnyData() { MockDemoBeanAnyDataWrapper mockData = JMockData.mock(MockDemoBeanAnyDataWrapper.class); // mockData.getJmockDataContext().printTree(); // 打印類型樹 mockData.setJmockDataContext(null); print(mockData); } /** * 測試模擬自循環(huán)引用的數(shù)據(jù) */ @Test public void mockTest_MockSelfRefData() { JMockDataManager.getInstance().setMaxSelfRefLevel(4);// 設(shè)置自循環(huán)體循環(huán)層級上限 MockDemoBeanSelfRefDataWrapper mockData = JMockData.mock(MockDemoBeanSelfRefDataWrapper.class); // mockData.getJmockDataContext().printTree(); // 打印類型樹 mockData.setJmockDataContext(null); print(mockData); } /** * 測試模擬類型攔截器,之?dāng)r截String類型的模擬 */ @Test public void mockTest_Interceptor() { JMockDataManager.getInstance().interceptors(OneJmockDataInterceptor.class); // 攔截器 =》只攔截String類型 MockDemoBeanSimpleDataWrapper mockData = JMockData.mock(MockDemoBeanSimpleDataWrapper.class); print(mockData.getSimpleData()); } /** * 測試模擬,增加自定義模擬類型,StringBuffer */ @Test public void mockTest_RegisterMockDataBean() { JMockDataManager.getInstance().registerMockData(new MockDataStringBuffer(), StringBuffer.class); MockDemoCustomStringBufferWrapper mockData = JMockData.mock(MockDemoCustomStringBufferWrapper.class); print(mockData.getStringBuffer()); } /** * 測試模擬,自定義模擬數(shù)據(jù)模板方法 */ @Test public void mockTest_CustomJmockDataTemplate() { JMockDataManager.getInstance().setMockTemplate(new CustomJmockDataTemplate()); MockDemoBeanSimpleDataWrapper mockData = JMockData.mock(MockDemoBeanSimpleDataWrapper.class); print(mockData.getSimpleData()); } /** * 打印json結(jié)構(gòu) * * @param data */ private void print(Object data) { System.out.println(JSON.toJSONString(data, true)); } }

配置文件config.properties 說明與使用

## value[seed,seed,seed]seedCharacter= 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y ZseedString= 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z## valueRange[min,max] / [fixed value]rangeShort=0,10rangeInteger=0,10# Double & BigdecimalrangeDouble=0.0,10.00 rangeFloat=0.0,10.00# Long & BigIntegerrangeLong=0.0,10.00## range-YMDhms[Y-min,Y-max,M-min,M-max,D-min,D-max,h-min,h-max,m-min,m-max,s-min,s-max]# default current yearrangeDateY=rangeDateM=0,12rangeDateD=0,30rangeDateH=0,60rangeDateMi=0,60rangeDateS=0,60# range-boolean [false,true] / [fixed value]rangeBoolean=false,true## arrSizeRange[arrSizeRange-min,arrSizeRange-max] / [fixed size]arrsizeBean=0,10arrsizeBigdecimal=0,10arrsizeBiginteger=0,10arrsizeBoolean=0,10arrsizeByte=0,10arrsizeCharacter=0,10arrsizeDate=0,10arrsizeDouble=0,10arrsizeFloat=0,10arrsizeInteger=0,10arrsizeLong=0,10arrsizeShort=0,10arrsizeString=0,10

代碼示例

/** * 測試配置文件 》 改變默認(rèn)算法行為 */ @Test public void mockTest_config() { JMockDataManager.getInstance().config("conf/config.properties"); // System.out.println(JSONObject.toJSONString(JMockDataManager.getInstance().config(),true)); MockDemoBeanConfigWrapper mockData = JMockData.mock(MockDemoBeanConfigWrapper.class); mockData.setJmockDataContext(null); print(mockData); }

開源中國>Jmockdata


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 嵩明县| 尼玛县| 策勒县| 托里县| 车致| 那坡县| 大埔县| 天台县| 寿宁县| 耒阳市| 永泰县| 嘉定区| 西吉县| 平果县| 临安市| 合阳县| 湟中县| 九江县| 富川| 阜城县| 衡山县| 十堰市| 定结县| 江北区| 囊谦县| 贺兰县| 梁河县| 双鸭山市| 松桃| 从化市| 德清县| 榆中县| 杭州市| 普安县| 沂源县| 大理市| 关岭| 蒲江县| 高密市| 军事| 阳高县|