In the test work, it is generally difficult to do complete testing, usually based on the boundary value, equivalence class partitioning method for the design of test data. In the actual test, some bugs may not be measured because of incomplete coverage. In this article I'm going to do a complete test of an interface that covers all paths.
Test ObjectHTTP interface: Http://..../common/getddd.do?
d1=d032&d2=d032034&d3=d032055 from the interface can be seen in the parameters passed in 3 layers of organization: D1,D2,D3. D1>D2>D3,D1 contains multiple d2,d2 that contain more than one d3,d1. So there is a lot of permutations here, and when the test data is directly organized, it will be very tedious. such as:So, try to simplify the test data generation process. Considering that D1,D2,D3 's organization relationship can be retrieved directly from the database, it is intended to use Hibernate to generate test data directly from the database.
generate test data by using hibernate to take an organization relationshipfrom the relational table, get the relationship between D1,D2,D3 and assemble into various combinations. Using Hibernate to traverse the database relational table, get a combination of all the d2,d3 below a D1 with the following code.
PublicStatic ArrayListGetList(String DeptID) {Urllist.add ("dept1=" +deptid); Session session = Hibernateutil.getsessionfactory (). Opensession (); Session.begintransaction (); Criteria CRITERIADEP2 = Session.createcriteria (Departmenttab.class); Criteria criteria2 = Session.createcriteria (Departmenttab.class); Criterion Criterion1 = Restrictions.eq ("ParentID", DeptID); Criteriadep2.add (Criterion1); List dept2list = Criteriadep2.list ();For (Ehrbidepartmenttab dept2:dept2list) {urllist.add ("dept1=" +deptid+"&" +"dept2=" + Dept2.getdeptid ());d Ept2idlist.add (Dept2.getdeptid ());} Logger.info (dept2idlist); Logger.info (urllist); For (int i = 0;i dept3list = Criteriadep3.list (); for (Ehrbidepartmenttab dept3:dept3list) {urllist.add ("dept1=" +deptid+"&" +"dept2=" + Dept2idlist.get (i) +"&" +"dept3=" +dept3.getdeptid ());} if (session!=null) {Session.close ();} return urllist;}
Get the following combination:
[INFO]16:11:45,833,main,[class]databaseutil, [Method]geturllist, [dept1=d032, dept1=d032&dept2=d032001, dept1=D032&dept2= D032002, dept1=d032&dept2=d032007, dept1=d032&dept2=d032008, dept1=d032&dept2=d032012, dept1=D032& dept2=d032016, dept1=d032&dept2=d032025, dept1=d032&dept2=d032029, dept1=d032&dept2=d032030, dept1= d032&dept2=d032034, dept1=d032&dept2=d032062, dept1=d032&dept2=d032002&dept3=d032009, dept1=D032 &dept2=d032002&dept3=d032010, dept1=d032&dept2=d032002&dept3=d032041, dept1=D032&dept2= d032007&dept3=d032014, dept1=d032&dept2=d032008&dept3=d032042, dept1=d032&dept2=d032008& dept3=d032043, dept1=d032&dept2=d032008&dept3=d032044, dept1=d032&dept2=d032008&dept3=d032045, dept1=d032&dept2=d032008&dept3=d032046, dept1=d032&dept2=d032008&dept3=d032047, dept1=D032& dept2=d032012&dept3=d032066, dept1=d032&dept2=d032025&dept3=d032026, dept1=D032&dept2=D032025&dept3=d032027, dept1=d032&dept2=d032025&dept3=d032028, dept1=d032&dept2=d032029&dept3=d032048, dept1=d032&dept2=d032029&dept3=d032049, dept1=d032&dept2=d032029&dept3=d032050, dept1=D032& dept2=d032029&dept3=d032052, dept1=d032&dept2=d032029&dept3=d032053, dept1=D032&dept2=D032029 &dept3=d032060, dept1=d032&dept2=d032029&dept3=d032063, dept1=d032&dept2=d032030&dept3= D032031, dept1=d032&dept2=d032030&dept3=d032032, dept1=d032&dept2=d032030&dept3=d032033, dept1= d032&dept2=d032034&dept3=d032036, dept1=d032&dept2=d032034&dept3=d032037, dept1=D032&dept2= d032034&dept3=d032040, dept1=d032&dept2=d032034&dept3=d032054, dept1=d032&dept2=d032034& dept3=d032055, dept1=d032&dept2=d032034&dept3=d032056, dept1=d032&dept2=d032034&dept3=d032057, dept1=d032&dept2=d032034&dept3=d032058, dept1=d032&dept2=d032034&dept3=d032059, dept1=D032& Dept2=d032034&dept3=d032061, dept1=d032&dept2=d032034&dept3=d032064]
With the above method, the complete test data can be obtained after traversing the first-level organization. Look at the following code:
Publicstatic ArrayList getalllist () { Session session = Hibernateutil.getsessionfactory (). Opensession (); Session.begintransaction (); Criteria criteriadep1 = Session.createcriteria (Ehrbidepartmenttab.class); Criteria criteria2 = Session.createcriteria (Ehrbidepartmenttab.class); Criterion Criterion1 = Restrictions.eq ( "depth", 1); Criteriadep1.add (Criterion1); List dept1list = Criteriadep1.list (); for (Departmenttab dept1:dept1list) {urllist.add ( "dept1=" + Dept1.getdeptid ());d Ept1idlist.add (Dept1.getdeptid ());} for (int i=0;i< Dept1idlist.size (); i++) {geturllist ((String) dept1idlist.get (i)); Session.close (); Logger.info (urllist); return urllist;}
看下面的返回结果:
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032001",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032002",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032007",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032012",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032016",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032025",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032030",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032062",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032002&dept3=D032009",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032002&dept3=D032010",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032002&dept3=D032041",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032007&dept3=D032014",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032042",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032043",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032044",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032045",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032046",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032008&dept3=D032047",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032012&dept3=D032066",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032025&dept3=D032026",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032025&dept3=D032027",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032025&dept3=D032028",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032048",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032049",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032050",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032052",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032053",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032060",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032029&dept3=D032063",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032030&dept3=D032031",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032030&dept3=D032032",0)
Passed:getddtest ("... By level One, level two, Level three ","Http://....netease.com/common/getdd.do?dept1=D032&dept2=D032030&dept3=D032033",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032036",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032037",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032040",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032054",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032055",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032056",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032057",0)
Passed:getddtest ("... By level One, level two, Level three ","http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034&dept3=D032058",0)
Passed:getddtest ( "... By first level, level two, level three department ", " http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034 &dept3=d032059 ", 0)
Passed:getddtest (" ... By first level, level two, level three department ", " http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034 &dept3=d032061 ", 0)
Passed:getddtest (" ... By first level, level two, level three department ", " http://....netease.com/common/getdd.do?dept1=D032&dept2=D032034 &dept3=d032064 ", 0)
===============================================
Default Test
Tests run: 47, Failures: 0, skips: 0
===============================================
这是一个d1下面的遍历结果,可想而知如果是几十个d1级别的组织需要遍历的数量是非常庞大的,如果通过手工编写测试数据的方式是没法进行全集测试的。
结论
通过使用Hibernate从数据库读取关系表的方法来获取多层组织的测试数据,进行全集测试的方法在一些项目中是可以适用的。
Complete test practice of HTTP interface based on hibernate