Hex Artifact Content

Artifact f4ef359685eaa4855bb9d7a2654e552dd1052b32:

Wiki page [Overview] by Entomy 2017-10-03 21:20:17.
0000: 44 20 32 30 31 37 2d 31 30 2d 30 33 54 32 31 3a  D 2017-10-03T21:
0010: 32 30 3a 31 37 2e 36 31 38 0a 4c 20 4f 76 65 72  20:17.618.L Over
0020: 76 69 65 77 0a 50 20 66 66 33 36 34 63 39 31 37  view.P ff364c917
0030: 65 64 31 33 38 30 38 65 39 32 34 62 38 62 33 62  ed13808e924b8b3b
0040: 65 34 64 65 61 36 66 37 34 34 35 64 32 31 38 0a  e4dea6f7445d218.
0050: 55 20 45 6e 74 6f 6d 79 0a 57 20 32 37 31 30 0a  U Entomy.W 2710.
0060: 3c 68 31 3e 42 6f 69 6c 65 72 70 6c 61 74 65 3c  <h1>Boilerplate<
0070: 2f 68 31 3e 0d 0a 3c 70 3e 4c 69 6b 65 20 61 6e  /h1>..<p>Like an
0080: 79 20 74 65 73 74 69 6e 67 20 66 72 61 6d 65 77  y testing framew
0090: 6f 72 6b 2c 20 73 6f 6d 65 20 62 6f 69 6c 65 72  ork, some boiler
00a0: 70 6c 61 74 65 20 6d 75 73 74 20 65 78 69 73 74  plate must exist
00b0: 2e 20 54 68 69 73 20 69 73 2c 20 73 69 6d 70 6c  . This is, simpl
00c0: 79 2c 20 73 65 74 74 69 6e 67 20 75 70 20 74 68  y, setting up th
00d0: 65 20 74 65 73 74 20 73 75 69 74 65 2c 20 61 6e  e test suite, an
00e0: 64 20 67 65 74 74 69 6e 67 20 74 68 65 20 66 69  d getting the fi
00f0: 6e 61 6c 20 72 65 73 75 6c 74 73 2e 3c 2f 70 3e  nal results.</p>
0100: 0d 0a 3c 70 3e 49 6e 20 61 6e 20 65 66 66 6f 72  ..<p>In an effor
0110: 74 20 74 6f 20 62 65 20 61 73 20 65 61 73 79 20  t to be as easy 
0120: 74 6f 20 75 73 65 20 61 73 20 70 6f 73 73 69 62  to use as possib
0130: 6c 65 2c 20 69 6e 69 74 69 61 6c 69 7a 61 74 69  le, initializati
0140: 6f 6e 20 69 73 20 6e 6f 74 68 69 6e 67 20 6d 6f  on is nothing mo
0150: 72 65 20 74 68 61 6e 20 61 20 63 61 6c 6c 20 74  re than a call t
0160: 6f 20 3c 63 6f 64 65 3e 53 74 61 72 74 3c 2f 63  o <code>Start</c
0170: 6f 64 65 3e 2e 20 54 68 69 73 20 70 72 6f 63 65  ode>. This proce
0180: 64 75 72 65 20 61 6c 77 61 79 73 20 61 63 63 65  dure always acce
0190: 70 74 73 20 74 68 65 20 75 6e 69 74 20 6e 61 6d  pts the unit nam
01a0: 65 20 74 6f 20 70 72 69 6e 74 20 74 6f 20 74 68  e to print to th
01b0: 65 20 6c 6f 67 2c 20 61 6e 64 20 74 68 65 20 6c  e log, and the l
01c0: 6f 67 20 6c 6f 63 61 74 69 6f 6e 20 77 68 69 63  og location whic
01d0: 68 20 69 73 20 73 74 61 6e 64 61 72 64 20 6f 75  h is standard ou
01e0: 74 70 75 74 20 62 79 20 64 65 66 61 75 6c 74 2e  tput by default.
01f0: 20 54 68 65 72 65 20 61 72 65 20 6f 74 68 65 72   There are other
0200: 20 6f 70 74 69 6f 6e 61 6c 20 70 61 72 61 6d 65   optional parame
0210: 74 65 72 73 2c 20 73 75 63 68 20 61 73 20 61 20  ters, such as a 
0220: 74 79 70 65 20 6e 61 6d 65 20 69 66 20 61 20 73  type name if a s
0230: 70 65 63 69 66 69 63 20 74 79 70 65 20 77 69 74  pecific type wit
0240: 68 69 6e 20 61 20 70 61 63 6b 61 67 65 20 69 73  hin a package is
0250: 20 62 65 69 6e 67 20 74 65 73 74 65 64 2e 3c 2f   being tested.</
0260: 70 3e 0d 0a 3c 70 3e 53 69 6d 69 6c 61 72 6c 79  p>..<p>Similarly
0270: 20 62 75 74 20 65 76 65 6e 20 73 69 6d 70 6c 65   but even simple
0280: 72 2c 20 74 68 65 20 65 6e 74 69 72 65 20 74 65  r, the entire te
0290: 73 74 20 73 75 69 74 65 20 69 73 20 66 69 6e 61  st suite is fina
02a0: 6c 69 7a 65 64 20 77 69 74 68 20 61 20 63 61 6c  lized with a cal
02b0: 6c 20 74 6f 20 3c 63 6f 64 65 3e 53 74 6f 70 3c  l to <code>Stop<
02c0: 2f 63 6f 64 65 3e 2e 20 54 68 65 72 65 20 61 72  /code>. There ar
02d0: 65 20 6e 6f 20 61 72 67 75 6d 65 6e 74 73 2e 20  e no arguments. 
02e0: 4a 75 73 74 20 6d 61 6b 65 20 73 75 72 65 20 79  Just make sure y
02f0: 6f 75 20 61 63 74 75 61 6c 6c 79 20 63 61 6c 6c  ou actually call
0300: 20 74 68 69 73 2e 3c 2f 70 3e 0d 0a 0d 0a 3c 68   this.</p>....<h
0310: 31 3e 41 73 73 65 72 74 69 6f 6e 73 3c 2f 68 31  1>Assertions</h1
0320: 3e 0d 0a 3c 70 3e 55 6e 6c 69 6b 65 20 6d 6f 73  >..<p>Unlike mos
0330: 74 20 3c 61 20 68 72 65 66 3d 22 68 74 74 70 3a  t <a href="http:
0340: 2f 2f 6a 75 6e 69 74 2e 6f 72 67 2f 6a 75 6e 69  //junit.org/juni
0350: 74 35 2f 22 3e 4a 55 6e 69 74 3c 2f 61 3e 20 62  t5/">JUnit</a> b
0360: 61 73 65 64 20 66 72 61 6d 65 77 6f 72 6b 73 2c  ased frameworks,
0370: 20 61 73 73 65 72 74 69 6f 6e 73 20 68 65 72 65   assertions here
0380: 20 61 72 65 20 64 6f 6e 65 20 74 68 72 6f 75 67   are done throug
0390: 68 20 71 75 65 73 74 69 6f 6e 2d 6c 69 6b 65 20  h question-like 
03a0: 70 72 6f 63 65 64 75 72 65 73 2e 20 46 6f 72 20  procedures. For 
03b0: 65 78 61 6d 70 6c 65 2c 20 65 71 75 61 6c 69 74  example, equalit
03c0: 79 20 69 73 6e 27 74 20 3c 63 6f 64 65 3e 41 73  y isn't <code>As
03d0: 73 65 72 74 28 31 2c 20 58 29 3c 2f 63 6f 64 65  sert(1, X)</code
03e0: 3e 2c 20 69 74 27 73 20 3c 63 6f 64 65 3e 49 73  >, it's <code>Is
03f0: 5f 45 71 75 61 6c 28 58 2c 20 31 29 3c 2f 63 6f  _Equal(X, 1)</co
0400: 64 65 3e 2e 20 46 6f 72 20 53 74 61 6e 64 61 72  de>. For Standar
0410: 64 20 74 79 70 65 73 2c 20 74 68 65 20 72 65 6c  d types, the rel
0420: 65 76 61 6e 74 20 6f 66 3a 20 3c 63 6f 64 65 3e  evant of: <code>
0430: 49 73 5f 45 71 75 61 6c 3c 2f 63 6f 64 65 3e 2c  Is_Equal</code>,
0440: 20 3c 63 6f 64 65 3e 49 73 5f 4e 6f 74 5f 45 71   <code>Is_Not_Eq
0450: 75 61 6c 3c 2f 63 6f 64 65 3e 2c 20 3c 63 6f 64  ual</code>, <cod
0460: 65 3e 49 73 5f 4c 65 73 73 65 72 3c 2f 63 6f 64  e>Is_Lesser</cod
0470: 65 3e 2c 20 3c 63 6f 64 65 3e 49 73 5f 4c 65 73  e>, <code>Is_Les
0480: 73 65 72 5f 4f 72 5f 45 71 75 61 6c 3c 2f 63 6f  ser_Or_Equal</co
0490: 64 65 3e 2c 20 3c 63 6f 64 65 3e 49 73 5f 47 72  de>, <code>Is_Gr
04a0: 65 61 74 65 72 3c 2f 63 6f 64 65 3e 2c 20 3c 63  eater</code>, <c
04b0: 6f 64 65 3e 49 73 5f 47 72 65 61 74 65 72 5f 4f  ode>Is_Greater_O
04c0: 72 5f 45 71 75 61 6c 3c 2f 63 6f 64 65 3e 20 61  r_Equal</code> a
04d0: 72 65 20 64 65 66 69 6e 65 64 2e 3c 2f 70 3e 0d  re defined.</p>.
04e0: 0a 3c 70 3e 41 6c 73 6f 20 75 6e 75 73 75 61 6c  .<p>Also unusual
04f0: 20 74 6f 20 6d 61 6e 79 2c 20 69 73 20 74 68 65   to many, is the
0500: 20 63 6f 6e 63 65 70 74 20 6f 66 20 70 72 6f 63   concept of proc
0510: 65 64 75 72 65 20 74 65 73 74 69 6e 67 2e 20 49  edure testing. I
0520: 6e 20 74 68 65 20 6d 61 6a 6f 72 69 74 79 20 6f  n the majority o
0530: 66 20 74 65 73 74 69 6e 67 20 66 72 61 6d 65 77  f testing framew
0540: 6f 72 6b 73 2c 20 74 65 73 74 73 20 6f 66 20 66  orks, tests of f
0550: 75 6e 63 74 69 6f 6e 73 20 6f 72 20 6d 65 74 68  unctions or meth
0560: 6f 64 73 20 69 73 20 61 6c 6c 20 74 68 61 74 20  ods is all that 
0570: 69 73 20 70 6f 73 73 69 62 6c 65 2c 20 62 65 63  is possible, bec
0580: 61 75 73 65 20 74 68 65 20 74 65 73 74 73 20 61  ause the tests a
0590: 72 65 20 64 6f 6e 65 20 61 67 61 69 6e 73 74 20  re done against 
05a0: 74 68 65 20 72 65 74 75 72 6e 65 64 20 76 61 6c  the returned val
05b0: 75 65 2e 20 50 72 6f 63 65 64 75 72 65 73 20 61  ue. Procedures a
05c0: 6e 64 20 73 6f 6d 65 20 4d 65 74 68 6f 64 73 20  nd some Methods 
05d0: 28 74 68 6f 73 65 20 74 68 61 74 20 72 65 74 75  (those that retu
05e0: 72 6e 20 76 6f 69 64 29 20 68 61 76 65 20 6e 6f  rn void) have no
05f0: 20 72 65 74 75 72 6e 65 64 20 76 61 6c 75 65 2c   returned value,
0600: 20 61 6e 64 20 73 6f 20 74 65 73 74 69 6e 67 20   and so testing 
0610: 74 68 6f 73 65 20 69 73 20 6e 6f 74 20 76 65 72  those is not ver
0620: 79 20 70 6f 73 73 69 62 6c 65 2c 20 72 69 67 68  y possible, righ
0630: 74 3f 20 4e 6f 70 65 2e 20 57 68 69 6c 65 20 77  t? Nope. While w
0640: 65 20 63 61 6e 27 74 20 70 72 6f 76 69 64 65 20  e can't provide 
0650: 74 68 65 6d 20 69 6e 20 61 6e 79 20 67 65 6e 65  them in any gene
0660: 72 69 63 20 77 61 79 2c 20 70 72 6f 63 65 64 75  ric way, procedu
0670: 72 65 20 61 73 73 65 72 74 69 6f 6e 73 20 61 72  re assertions ar
0680: 65 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 61 73  e implemented as
0690: 20 63 68 69 6c 64 20 70 61 63 6b 61 67 65 73 20   child packages 
06a0: 61 6c 6f 6e 67 20 77 69 74 68 20 61 6e 79 20 6f  along with any o
06b0: 74 68 65 72 20 5b 45 78 74 65 6e 64 69 6e 67 7c  ther [Extending|
06c0: 45 78 74 65 6e 73 69 6f 6e 73 5d 2e 20 54 68 65  Extensions]. The
06d0: 72 65 20 61 72 65 20 74 77 6f 20 72 65 6c 65 76  re are two relev
06e0: 61 6e 74 20 63 68 6f 69 63 65 73 20 3c 63 6f 64  ant choices <cod
06f0: 65 3e 50 61 73 73 65 73 3c 2f 63 6f 64 65 3e 20  e>Passes</code> 
0700: 61 6e 64 20 3c 63 6f 64 65 3e 46 61 69 6c 73 3c  and <code>Fails<
0710: 2f 63 6f 64 65 3e 2e 20 54 68 65 20 70 61 72 61  /code>. The para
0720: 6d 65 74 65 72 20 73 79 6e 74 61 78 20 69 73 20  meter syntax is 
0730: 61 6c 6d 6f 73 74 20 65 6e 74 69 72 65 6c 79 20  almost entirely 
0740: 64 65 70 65 6e 64 65 6e 74 20 6f 6e 20 77 68 61  dependent on wha
0750: 74 20 69 73 20 62 65 69 6e 67 20 63 61 6c 6c 65  t is being calle
0760: 64 2c 20 61 6e 64 20 69 6e 76 6f 6c 76 65 73 20  d, and involves 
0770: 70 72 6f 63 65 64 75 72 65 20 61 63 63 65 73 73  procedure access
0780: 20 63 61 6c 6c 73 2c 20 73 6f 20 69 74 20 69 73   calls, so it is
0790: 20 6e 6f 74 20 66 6f 72 20 6e 6f 76 69 63 65 20   not for novice 
07a0: 70 72 6f 67 72 61 6d 6d 65 72 73 2e 20 4d 61 6e  programmers. Man
07b0: 79 20 70 72 6f 63 65 64 75 72 65 20 61 73 73 65  y procedure asse
07c0: 72 74 69 6f 6e 73 20 61 6c 73 6f 20 69 6e 63 6c  rtions also incl
07d0: 75 64 65 20 61 20 3c 63 6f 64 65 3e 44 75 6d 70  ude a <code>Dump
07e0: 3c 2f 63 6f 64 65 3e 20 70 61 72 61 6d 65 74 65  </code> paramete
07f0: 72 2c 20 77 68 69 63 68 20 73 70 65 63 69 66 69  r, which specifi
0800: 65 73 20 77 68 65 74 68 65 72 20 74 6f 20 69 6e  es whether to in
0810: 63 6c 75 64 65 2c 20 69 6e 20 74 65 78 74 20 66  clude, in text f
0820: 6f 72 6d 2c 20 74 68 65 20 6d 61 6a 6f 72 20 74  orm, the major t
0830: 79 70 65 20 74 68 65 20 70 72 6f 63 65 64 75 72  ype the procedur
0840: 65 20 69 73 20 6f 70 65 72 61 74 69 6e 67 20 75  e is operating u
0850: 70 6f 6e 2c 20 61 66 74 65 72 20 74 68 65 20 70  pon, after the p
0860: 72 6f 63 65 64 75 72 65 20 63 61 6c 6c 3b 20 74  rocedure call; t
0870: 68 69 73 20 69 73 20 6f 62 76 69 6f 75 73 6c 79  his is obviously
0880: 20 65 78 74 72 65 6d 65 6c 79 20 75 73 65 66 75   extremely usefu
0890: 6c 20 66 6f 72 20 74 65 73 74 69 6e 67 20 74 68  l for testing th
08a0: 69 6e 67 73 20 6c 69 6b 65 20 63 6f 6e 74 61 69  ings like contai
08b0: 6e 65 72 73 2c 20 77 68 65 72 65 20 79 6f 75 20  ners, where you 
08c0: 63 61 6e 20 73 65 65 20 74 68 65 20 61 66 74 20  can see the aft 
08d0: 6f 66 20 74 68 65 20 6f 70 65 72 61 74 69 6f 6e  of the operation
08e0: 2e 3c 2f 70 3e 0d 0a 0d 0a 3c 68 31 3e 54 69 6d  .</p>....<h1>Tim
08f0: 69 6e 67 3c 2f 68 31 3e 0d 0a 3c 70 3e 57 68 69  ing</h1>..<p>Whi
0900: 6c 65 20 73 74 69 6c 6c 20 61 6e 20 69 6d 70 6f  le still an impo
0910: 72 74 61 6e 74 20 70 61 72 74 20 6f 66 20 73 6f  rtant part of so
0920: 66 74 77 61 72 65 20 74 65 73 74 69 6e 67 2c 20  ftware testing, 
0930: 63 6f 64 65 20 74 69 6d 65 72 73 20 61 72 65 20  code timers are 
0940: 67 65 6e 65 72 61 6c 6c 79 20 6e 6f 74 20 69 6e  generally not in
0950: 63 6c 75 64 65 64 20 69 6e 20 74 65 73 74 69 6e  cluded in testin
0960: 67 20 66 72 61 6d 65 77 6f 72 6b 73 2e 20 54 68  g frameworks. Th
0970: 61 74 27 73 20 6e 6f 74 20 74 68 65 20 63 61 73  at's not the cas
0980: 65 20 68 65 72 65 2e 20 41 20 62 61 73 65 20 3c  e here. A base <
0990: 63 6f 64 65 3e 54 69 6d 65 72 3c 2f 63 6f 64 65  code>Timer</code
09a0: 3e 20 65 78 69 73 74 73 20 69 6e 20 61 62 73 74  > exists in abst
09b0: 72 61 63 74 20 66 6f 72 6d 2c 20 77 69 74 68 20  ract form, with 
09c0: 74 77 6f 20 69 6e 73 74 61 6e 63 65 73 3a 20 3c  two instances: <
09d0: 63 6f 64 65 3e 52 65 61 6c 5f 54 69 6d 65 72 3c  code>Real_Timer<
09e0: 2f 63 6f 64 65 3e 20 61 6e 64 20 3c 63 6f 64 65  /code> and <code
09f0: 3e 45 78 65 63 75 74 69 6f 6e 5f 54 69 6d 65 72  >Execution_Timer
0a00: 3c 2f 63 6f 64 65 3e 20 77 68 69 63 68 20 6d 65  </code> which me
0a10: 61 73 75 72 65 20 74 68 65 69 72 20 72 65 73 70  asure their resp
0a20: 65 63 74 69 76 65 20 74 69 6d 65 73 2e 20 54 68  ective times. Th
0a30: 65 73 65 20 70 72 6f 76 69 64 65 20 3c 63 6f 64  ese provide <cod
0a40: 65 3e 53 74 61 72 74 3c 2f 63 6f 64 65 3e 20 61  e>Start</code> a
0a50: 6e 64 20 3c 63 6f 64 65 3e 53 74 6f 70 3c 2f 63  nd <code>Stop</c
0a60: 6f 64 65 3e 20 63 61 6c 6c 73 20 6a 75 73 74 20  ode> calls just 
0a70: 6c 69 6b 65 20 61 20 73 74 6f 70 20 77 61 74 63  like a stop watc
0a80: 68 20 77 6f 75 6c 64 20 75 73 65 2c 20 61 73 20  h would use, as 
0a90: 77 65 6c 6c 20 61 73 20 3c 63 6f 64 65 3e 52 75  well as <code>Ru
0aa0: 6e 5f 54 69 6d 65 3c 2f 63 6f 64 65 3e 20 77 68  n_Time</code> wh
0ab0: 69 63 68 20 67 65 74 73 20 68 6f 77 20 6c 6f 6e  ich gets how lon
0ac0: 67 20 74 68 65 20 74 69 6d 65 72 20 72 61 6e 20  g the timer ran 
0ad0: 66 6f 72 20 61 73 20 74 68 65 20 53 74 61 6e 64  for as the Stand
0ae0: 61 72 64 20 44 75 72 61 74 69 6f 6e 20 74 79 70  ard Duration typ
0af0: 65 2e 3c 2f 70 3e 0a 5a 20 61 35 31 65 34 36 64  e.</p>.Z a51e46d
0b00: 36 37 36 65 39 61 37 64 63 65 65 66 34 62 34 66  676e9a7dceef4b4f
0b10: 34 65 62 31 30 37 35 61 37 0a                    4eb1075a7.