PageRenderTime 63ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/source/en/overview.xml

https://github.com/francois2metz/simpletest
XML | 455 lines | 451 code | 3 blank | 1 comment | 0 complexity | 8d19e2beda58da4839e9801d38143ee2 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?xml version="1.0"?>
  2. <!-- $Id$ -->
  3. <page title="Overview of SimpleTest" here="Overview">
  4. <long_title>
  5. Overview and feature list for the SimpleTest PHP unit tester and web tester
  6. </long_title>
  7. <content>
  8. <section name="summary" title="What is SimpleTest?">
  9. <p>
  10. The heart of SimpleTest is a testing framework built around
  11. test case classes.
  12. These are written as extensions of base test case classes,
  13. each extended with methods that actually contain test code.
  14. Each test method of a test case class is written to invoke
  15. various assertions that the developer expects to be true such as
  16. <code>assertEqual()</code>.
  17. If the expectation is correct, then a successful result is
  18. dispatched to the observing test reporter, but any failure
  19. or unexpected exception triggers an alert and a description
  20. of the mismatch.
  21. These test case declarations are transformed into executable
  22. test scripts by including a SimpleTest aurorun.php file.
  23. </p>
  24. <p>
  25. These documents apply to SimpleTest version 1.1, although we
  26. try hard to maintain compatibility between versions.
  27. If you get a test failure after an upgrade, check out the
  28. file &quot;HELP_MY_TESTS_DONT_WORK_ANYMORE&quot; in the
  29. simpletest directory to see if a feature you are using
  30. has since been deprecated and later removed.
  31. </p>
  32. <p>
  33. A <a local="unit_test_documentation">test case</a> looks like this...
  34. <php><![CDATA[
  35. <?php
  36. require_once('simpletest/autorun.php');
  37. class <strong>CanAddUp</strong> extends UnitTestCase {<strong>
  38. function testWillCreateLogFileOnFirstMessage() {
  39. $this->assertEqual(1 + 1, 2);
  40. }</strong>
  41. }
  42. ?>
  43. ]]></php>
  44. Tests are grouped into test cases, which are just
  45. PHP classes that extend <code>UnitTestCase</code>
  46. or <code>WebTestCase</code>.
  47. The tests themselves are just normal methods that start
  48. their name with the letters &quot;test&quot;.
  49. You can have as many test cases as you want in a test
  50. script and each test case can have as many test methods
  51. as it wants too.
  52. </p>
  53. <p>
  54. This test script is immediately runnable.
  55. </p>
  56. <p>
  57. When run on the command line you should see something like...
  58. <pre class="shell">
  59. adding_test.php
  60. OK
  61. Test cases run: 1/1, Passes: 1, Failures: 0, Exceptions: 0
  62. </pre>
  63. </p>
  64. <p>
  65. If you place it on a web server and point your
  66. web browser at it...
  67. <div class="demo">
  68. <h1>adding_test.php</h1>
  69. <div style="padding: 8px; margin-top: 1em; background-color: green; color: white;">1/1 test cases complete.
  70. <strong>6</strong> passes, <strong>0</strong> fails and <strong>0</strong> exceptions.</div>
  71. </div>
  72. </p>
  73. <p>
  74. Of course this is a silly example.
  75. A more realistic example might be...
  76. <php><![CDATA[
  77. <?php
  78. require_once('simpletest/autorun.php');
  79. require_once('log.php');
  80. class <strong>TestOfLogging</strong> extends UnitTestCase {
  81. function testWillCreateLogFileOnFirstMessage() {
  82. $log = new Log('my.log');
  83. $this->assertFalse(file_exists('my.log'));
  84. $log->message('Hello');
  85. $this->assertTrue(file_exists('my.log'));
  86. }</strong>
  87. }
  88. ?>
  89. ]]></php>
  90. </p>
  91. <p>
  92. This tool is designed for the developer.
  93. The target audience of this tool is anyone developing a small
  94. to medium PHP application, including developers new to
  95. unit and web regression testing.
  96. The core principles are ease of use first, with extendibility and
  97. essential features.
  98. </p>
  99. <p>
  100. Tests are written in the PHP language itself more or less
  101. as the application itself is built.
  102. The advantage of using PHP as the testing language is that
  103. there are no new languages to learn, testing can start straight away,
  104. and the developer can test any part of the code.
  105. Basically, all parts that can be accessed by the application code can also be
  106. accessed by the test code when they are in the same programming language.
  107. </p>
  108. <p>
  109. The simplest type of test case is the
  110. <a local="unit_tester_documentation">UnitTestCase</a>.
  111. This class of test case includes standard tests for equality,
  112. references and pattern matching.
  113. All these test the typical expectations of what you would
  114. expect the result of a function or method to be.
  115. This is by far the most common type of test in the daily
  116. routine of development, making up about 95% of test cases.
  117. </p>
  118. <p>
  119. The top level task of a web application though is not to
  120. produce correct output from its methods and objects, but
  121. to generate web pages.
  122. The <a local="web_tester_documentation">WebTestCase</a> class tests web
  123. pages.
  124. It simulates a web browser requesting a page, complete with
  125. cookies, proxies, secure connections, authentication, forms, frames and most
  126. navigation elements.
  127. With this type of test case, the developer can assert that
  128. information is present in the page and that forms and
  129. sessions are handled correctly.
  130. </p>
  131. <p>
  132. A <a local="web_tester_documentation">WebTestCase</a> looks like this...
  133. <php><![CDATA[
  134. <?php
  135. require_once('simpletest/autorun.php');
  136. require_once('simpletest/web_tester.php');
  137. class <strong>MySiteTest</strong> extends WebTestCase {
  138. <strong>
  139. function testHomePageHasContactDetails() {
  140. $this->get('http://www.my-site.com/index.php');
  141. $this->assertTitle('My Home Page');
  142. $this->clickLink('Contact');
  143. $this->assertTitle('Contact me');
  144. $this->assertText('/Email me at/');
  145. }</strong>
  146. }
  147. ?>
  148. ]]></php>
  149. </p>
  150. </section>
  151. <section name="features" title="Feature list">
  152. <p>
  153. The following is a very rough outline of past and future features
  154. and their expected point of release.
  155. I am afraid it is liable to change without warning, as meeting the
  156. milestones rather depends on time available.
  157. </p>
  158. <p>
  159. Green stuff has been coded, but not necessarily released yet.
  160. If you have a pressing need for a green but unreleased feature
  161. then you should check-out the code from Sourceforge SVN directly.
  162. <table><thead>
  163. <tr><th>Feature</th><th>Description</th><th>Release</th></tr>
  164. </thead><tbody><tr>
  165. <td>Unit test case</td>
  166. <td>Core test case class and assertions</td>
  167. <td style="color: green;">1.0</td>
  168. </tr>
  169. <tr>
  170. <td>Html display</td>
  171. <td>Simplest possible display</td>
  172. <td style="color: green;">1.0</td>
  173. </tr>
  174. <tr>
  175. <td>Autoloading of test cases</td>
  176. <td>
  177. Reading a file with test cases and loading them into a
  178. group test automatically
  179. </td>
  180. <td style="color: green;">1.0</td>
  181. </tr>
  182. <tr>
  183. <td>Mock objects</td>
  184. <td>
  185. Objects capable of simulating other objects removing
  186. test dependencies
  187. </td>
  188. <td style="color: green;">1.0</td>
  189. </tr>
  190. <tr>
  191. <td>Web test case</td>
  192. <td>Allows link following and title tag matching</td>
  193. <td style="color: green;">1.0</td>
  194. </tr>
  195. <tr>
  196. <td>Partial mocks</td>
  197. <td>
  198. Mocking parts of a class for testing less than a class
  199. or for complex simulations
  200. </td>
  201. <td style="color: green;">1.0</td>
  202. </tr>
  203. <tr>
  204. <td>Web cookie handling</td>
  205. <td>Correct handling of cookies when fetching pages</td>
  206. <td style="color: green;">1.0</td>
  207. </tr>
  208. <tr>
  209. <td>Following redirects</td>
  210. <td>Page fetching automatically follows 300 redirects</td>
  211. <td style="color: green;">1.0</td>
  212. </tr>
  213. <tr>
  214. <td>Form parsing</td>
  215. <td>Ability to submit simple forms and read default form values</td>
  216. <td style="color: green;">1.0</td>
  217. </tr>
  218. <tr>
  219. <td>Command line interface</td>
  220. <td>Test display without the need of a web browser</td>
  221. <td style="color: green;">1.0</td>
  222. </tr>
  223. <tr>
  224. <td>Exposure of expectation classes</td>
  225. <td>Can create precise tests with mocks as well as test cases</td>
  226. <td style="color: green;">1.0</td>
  227. </tr>
  228. <tr>
  229. <td>XML output and parsing</td>
  230. <td>
  231. Allows multi host testing and the integration of acceptance
  232. testing extensions
  233. </td>
  234. <td style="color: green;">1.0</td>
  235. </tr>
  236. <tr>
  237. <td>Browser component</td>
  238. <td>
  239. Exposure of lower level web browser interface for more
  240. detailed test cases
  241. </td>
  242. <td style="color: green;">1.0</td>
  243. </tr>
  244. <tr>
  245. <td>HTTP authentication</td>
  246. <td>
  247. Fetching protected web pages with basic authentication
  248. only
  249. </td>
  250. <td style="color: green;">1.0</td>
  251. </tr>
  252. <tr>
  253. <td>SSL support</td>
  254. <td>Can connect to https: pages</td>
  255. <td style="color: green;">1.0</td>
  256. </tr>
  257. <tr>
  258. <td>Proxy support</td>
  259. <td>Can connect via. common proxies</td>
  260. <td style="color: green;">1.0</td>
  261. </tr>
  262. <tr>
  263. <td>Frames support</td>
  264. <td>Handling of frames in web test cases</td>
  265. <td style="color: green;">1.0</td>
  266. </tr>
  267. <tr>
  268. <td>File upload testing</td>
  269. <td>Can simulate the input type file tag</td>
  270. <td style="color: green;">1.0.1</td>
  271. </tr>
  272. <tr>
  273. <td>Mocking interfaces</td>
  274. <td>
  275. Can generate mock objects to interfaces as well as classes
  276. and class interfaces are carried for type hints
  277. </td>
  278. <td style="color: green;">1.0.1</td>
  279. </tr>
  280. <tr>
  281. <td>Testing exceptions</td>
  282. <td>Similar to testing PHP errors</td>
  283. <td style="color: green;">1.0.1</td>
  284. </tr>
  285. <tr>
  286. <td>HTML label support</td>
  287. <td>Can access all controls using the visual label</td>
  288. <td style="color: green;">1.0.1</td>
  289. </tr>
  290. <tr>
  291. <td>Base tag support</td>
  292. <td>Respects page base tag when clicking</td>
  293. <td style="color: green;">1.0.1</td>
  294. </tr>
  295. <tr>
  296. <td>PHP 5 E_STRICT compliant</td>
  297. <td>PHP 5 only version that works with the E_STRICT error level</td>
  298. <td style="color: green;">1.1</td>
  299. </tr>
  300. <tr>
  301. <td>Alternate HTML parsers</td>
  302. <td>Can detect compiled parsers for performance improvements</td>
  303. <td style="color: green;">1.1</td>
  304. </tr>
  305. <tr>
  306. <td>REST support</td>
  307. <td>Support for REST verbs as put(), delete(), etc.</td>
  308. <td style="color: green;">1.1</td>
  309. </tr>
  310. <tr>
  311. <td>BDD style fixtures</td>
  312. <td>Can import fixtures using a mixin like given() method</td>
  313. <td style="color: red;">1.5</td>
  314. </tr>
  315. <tr>
  316. <td>Plug-in architecture</td>
  317. <td>Automatic import of extensions including command line options</td>
  318. <td style="color: red;">1.5</td>
  319. </tr>
  320. <tr>
  321. <td>Reporting machinery enhancements</td>
  322. <td>Improved message passing for better cooperation with IDEs</td>
  323. <td style="color: red;">1.5</td>
  324. </tr>
  325. <tr>
  326. <td>Fluent mock interface</td>
  327. <td>More flexible and concise mock objects</td>
  328. <td style="color: red;">1.6</td>
  329. </tr>
  330. <tr>
  331. <td>Localisation</td>
  332. <td>Messages abstracted and code generated as well as UTF support</td>
  333. <td style="color: red;">1.6</td>
  334. </tr>
  335. <tr>
  336. <td>CSS selectors</td>
  337. <td>HTML content can be examined using CSS selectors</td>
  338. <td style="color: red;">1.7</td>
  339. </tr>
  340. <tr>
  341. <td>HTML table assertions</td>
  342. <td>Can match HTML or table elements to expectations</td>
  343. <td style="color: red;">1.7</td>
  344. </tr>
  345. <tr>
  346. <td>Unified acceptance testing model</td>
  347. <td>Content searchable through selectors combined with expectations</td>
  348. <td style="color: red;">1.7</td>
  349. </tr>
  350. <tr>
  351. <td>DatabaseTestCase</td>
  352. <td>SQL selectors and DB drivers</td>
  353. <td style="color: red;">1.7</td>
  354. </tr>
  355. <tr>
  356. <td>IFrame support</td>
  357. <td>Reads IFrame content that can be refreshed</td>
  358. <td style="color: red;">1.8</td>
  359. </tr>
  360. <tr>
  361. <td>Integrated Selenium support</td>
  362. <td>Easy to use built in Selenium driver and tutorial or similar browser automation</td>
  363. <td style="color: red;">1.9</td>
  364. </tr>
  365. <tr>
  366. <td>Code coverage</td>
  367. <td>Reports using the bundled tool when using XDebug</td>
  368. <td style="color: red;">1.9</td>
  369. </tr>
  370. <tr>
  371. <td>Deprecation of old methods</td>
  372. <td>Simpler interface for SimpleTest2</td>
  373. <td style="color: red;">2.0</td>
  374. </tr>
  375. <tr>
  376. <td>Javascript suport</td>
  377. <td>Use of PECL module to add Javascript to the native browser</td>
  378. <td style="color: red;">3.0</td>
  379. </tr>
  380. </tbody></table>
  381. PHP 5 migration is complete, which means that only PHP 5.0.3+
  382. will be supported in SimpleTest version 1.1+.
  383. Earlier versions of SimpleTest are compatible with PHP 4.2 up to
  384. PHP 5 (non E_STRICT).
  385. </p>
  386. </section>
  387. </content>
  388. <internal>
  389. <link>
  390. <a href="#summary">Quick summary</a>
  391. of the SimpleTest tool for PHP.
  392. </link>
  393. <link>
  394. <a href="#features">List of features</a>,
  395. both current ones and those planned.
  396. </link>
  397. </internal>
  398. <external>
  399. <link>
  400. <a local="unit_test_documentation">Documentation for SimpleTest</a>.
  401. </link>
  402. <link>
  403. <a href="http://www.lastcraft.com/first_test_tutorial.php">How to write PHP test cases</a>
  404. is a fairly advanced tutorial.
  405. </link>
  406. <link>
  407. <a href="http://simpletest.org/api/">SimpleTest API</a> from phpdoc.
  408. </link>
  409. </external>
  410. <meta>
  411. <keywords>
  412. software development tools,
  413. php programming,
  414. programming php,
  415. software development tools,
  416. Tools for extreme programming,
  417. free php scripts,
  418. links of testing tools,
  419. php testing resources,
  420. mock objects,
  421. junit,
  422. jwebunit,
  423. htmlunit,
  424. itc,
  425. php testing links,
  426. unit test advice and documentation,
  427. extreme programming in php
  428. </keywords>
  429. </meta>
  430. <refsynopsisdiv>
  431. <authorgroup>
  432. <author>
  433. Marcus Baker
  434. <authorblurb>
  435. <para>Primary Developer</para><para>{@link mailto:marcus@lastcraft.com marcus@lastcraft.com}</para>
  436. </authorblurb>
  437. </author>
  438. <author>
  439. Perrick Pennet
  440. <authorblurb>
  441. <para>General manager</para><para>{@link mailto:perrick@noparking.net perrick@noparking.net}</para>
  442. </authorblurb>
  443. </author>
  444. <author>
  445. Jason Sweat
  446. <authorblurb>
  447. <para>Documentation</para><para>{@link mailto:jsweat_php@yahoo.com jsweat_php@yahoo.com}</para>
  448. </authorblurb>
  449. </author>
  450. </authorgroup>
  451. </refsynopsisdiv>
  452. </page>