Counterstrings: Self-Describing Test Data
昨天去James Bach的Blog,看到有关Couterstrings的描述:
“A counterstring is a graduated string of arbitrary length. No matter where
you are in the string, you always know the character position. This comes in
handy when you are pasting huge strings into fields and they get truncated
at a certain point. You want to know how many characters that is.
Here is a 35 character counterstring:
2*4*6*8*11*14*17*20*23*26*29*32*35*
Each asterisk in the string occurs at a position specified by the immediately
preceding number. Thus, the asterisk following the 29 is the 29th character
in that string. So, you can chop the end of the string anywhere, and you know
exactly where it was cut. Without having to count, you know that the string
“2*4*6*8*11*14*17*2″ has exactly 18 characters in it. This saves some effort
when you’re dealing with a half million characters. I pasted a 4000 character
counterstring into the address field of Explorer and it was truncated at
“2045*20″, meaning that 2047 characters were pasted.
I realize this is may not be a very interesting sort of testing, except perhaps
for security purposes or when you’re first getting to know the app. But security
is an increasingly important issue in our field, and sometimes when no one tells
you the limits and dynamics of text fields, this can come in handy. ”
利用James Bach提供的一个小工具PerlClip做了一个小小的测试,具体如下:
使用PerlClip生成1000位的Counterstrings,见下面的数据:
*3*5*7*9*12*15*18*21*24*27*30*33*36*39*42*45*48*51*54*57*60*63*66*69*72*75*78
*81*84*87*90*93*96*99*103*107*111*115*119*123*127*131*135*139*143*147*151*155
*159*163*167*171*175*179*183*187*191*195*199*203*207*211*215*219*223*227*231
*235*239*243*247*251*255*259*263*267*271*275*279*283*287*291*295*299*303*307
*311*315*319*323*327*331*335*339*343*347*351*355*359*363*367*371*375*379*383
*387*391*395*399*403*407*411*415*419*423*427*431*435*439*443*447*451*455*459
*463*467*471*475*479*483*487*491*495*499*503*507*511*515*519*523*527*531*535
*539*543*547*551*555*559*563*567*571*575*579*583*587*591*595*599*603*607*611
*615*619*623*627*631*635*639*643*647*651*655*659*663*667*671*675*679*683*687
*691*695*699*703*707*711*715*719*723*727*731*735*739*743*747*751*755*759*763
*767*771*775*779*783*787*791*795*799*803*807*811*815*819*823*827*831*835*839
*843*847*851*855*859*863*867*871*875*879*883*887*891*895*899*903*907*911*915
*919*923*927*931*935*939*943*947*951*955*959*963*967*971*975*979*983*987*991
*995*1000*
将此数据输入到baidu的搜索框中:
搜索框会自动截断至*3*5*7*9*12*15*18*21*24*27*30*33*36*39*42*45*48*51*54
*57*60*63*66*69*72*75*78*81*84*87*90*93*96*99*1
上面这段数据告诉我们baidu的搜索框中最多只能输入100个char(由于此段数据以1位星号开始,因此,99位处实际应为99-1位,所以总共100位,并不是101位)。
那么我们在输入了100位char之后,点击“百度搜索”会如何呢?
*3*5*7*9*12*15*18*21*24*27*30*33*36*39*42*45*48*51*54*57*60*63*66*69*72*75*7
被系统自动截断为76位(原因如上所述),同时,baidu会有一个系统提示,如下:
“提示:"8*8" 及其后面的字词均被忽略,因为百度的查询限制在38个汉字以内。”
这里要说明一点,一个汉字有两个字符组成,因此,38*2=76,与第二次截断后的数据所描述的长度完全一致。
(PS:这种测试下,baidu的表现要比Google的好,虽然Google的搜索框第一次截断的char长度比baidu大的多,一直可以到2045*205,一共2048位,但是,当我点击搜索之后,Google要么全无反应,要么报错说我的网络链接有问题。)
厚厚,很有意思的counterstring,当然仁者见仁智者见智,该什么时候用它、该怎么用它来帮助我们测试,大家还是自己看着办吧。
(PS:无论counterstring是一种数据类型,还是一种生成数据的函数或是方法,我想重点还是我们应该如何应用它,来更好地为我们的测试服务。)