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)系我, 作者:jsonzouJmockdata-2.0
Jmockdata-1.0
具體示例請參考:https://github.com/jsonzou/jmockdata-demo或者下載該示例項目Please refer to the specific example:https://github.com/jsonzou/jmockdata-demo Ordownload the demo PRoject>
代碼示例
/** * 測試配置文件 》 改變默認(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
新聞熱點
疑難解答