aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/Running-unit-tests.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/Running-unit-tests.html')
-rw-r--r--doc/Running-unit-tests.html143
1 files changed, 143 insertions, 0 deletions
diff --git a/doc/Running-unit-tests.html b/doc/Running-unit-tests.html
new file mode 100644
index 00000000..43423bc7
--- /dev/null
+++ b/doc/Running-unit-tests.html
@@ -0,0 +1,143 @@
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <meta name="generator" content="pandoc">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
7 <title></title>
8 <style type="text/css">code{white-space: pre;}</style>
9 <!--[if lt IE 9]>
10 <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
11 <![endif]-->
12 <style type="text/css">
13table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
14 margin: 0; padding: 0; vertical-align: baseline; border: none; }
15table.sourceCode { width: 100%; line-height: 100%; }
16td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
17td.sourceCode { padding-left: 5px; }
18code > span.kw { color: #007020; font-weight: bold; }
19code > span.dt { color: #902000; }
20code > span.dv { color: #40a070; }
21code > span.bn { color: #40a070; }
22code > span.fl { color: #40a070; }
23code > span.ch { color: #4070a0; }
24code > span.st { color: #4070a0; }
25code > span.co { color: #60a0b0; font-style: italic; }
26code > span.ot { color: #007020; }
27code > span.al { color: #ff0000; font-weight: bold; }
28code > span.fu { color: #06287e; }
29code > span.er { color: #ff0000; font-weight: bold; }
30 </style>
31 <link rel="stylesheet" href="github-markdown.css">
32</head>
33<body>
34<h3 id="setup-your-environment-for-tests">Setup your environment for tests</h3>
35<p>The framework used is <a href="https://phpunit.de/">PHPUnit</a>; it can be installed with <a href="https://getcomposer.org/">Composer</a>, which is a dependency management tool.</p>
36<p>Regarding Composer, you can either use:</p>
37<ul>
38<li>a system-wide version, e.g. installed through your distro's package manager<br /></li>
39<li>a local version, downloadable <a href="https://getcomposer.org/download/">here</a></li>
40</ul>
41<h4 id="sample-usage">Sample usage</h4>
42<pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># system-wide version</span>
43$ <span class="kw">composer</span> install
44$ <span class="kw">composer</span> update
45
46<span class="co"># local version</span>
47$ <span class="kw">php</span> composer.phar self-update
48$ <span class="kw">php</span> composer.phar install
49$ <span class="kw">php</span> composer.phar update</code></pre>
50<h4 id="install-shaarli-dev-dependencies">Install Shaarli dev dependencies</h4>
51<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">cd</span> /path/to/shaarli
52$ <span class="kw">composer</span> update</code></pre>
53<h4 id="install-and-enable-xdebug-to-generate-phpunit-coverage-reports">Install and enable Xdebug to generate PHPUnit coverage reports</h4>
54<p>For Debian-based distros:</p>
55<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">aptitude</span> install php5-xdebug</code></pre>
56<p>For ArchLinux:</p>
57<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">pacman</span> -S xdebug</code></pre>
58<p>Then add the following line to <code>/etc/php/php.ini</code>:</p>
59<pre class="sourceCode ini"><code class="sourceCode ini"><span class="dt">zend_extension</span><span class="ot">=</span><span class="st">xdebug.so</span></code></pre>
60<h4 id="run-unit-tests">Run unit tests</h4>
61<p>Successful test suite:</p>
62<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">make</span> test
63
64<span class="kw">-------</span>
65<span class="kw">PHPUNIT</span>
66<span class="kw">-------</span>
67<span class="kw">PHPUnit</span> 4.6.9 by Sebastian Bergmann and contributors.
68
69<span class="kw">Configuration</span> read from /home/virtualtam/public_html/shaarli/phpunit.xml
70
71<span class="kw">....................................</span>
72
73<span class="kw">Time</span>: 759 ms, Memory: 8.25Mb
74
75<span class="kw">OK</span> (36 tests, 65 assertions)</code></pre>
76<p>Test suite with failures and errors:</p>
77<pre class="sourceCode bash"><code class="sourceCode bash">$ <span class="kw">make</span> test
78<span class="kw">-------</span>
79<span class="kw">PHPUNIT</span>
80<span class="kw">-------</span>
81<span class="kw">PHPUnit</span> 4.6.9 by Sebastian Bergmann and contributors.
82
83<span class="kw">Configuration</span> read from /home/virtualtam/public_html/shaarli/phpunit.xml
84
85<span class="kw">E..FF...............................</span>
86
87<span class="kw">Time</span>: 802 ms, Memory: 8.25Mb
88
89<span class="kw">There</span> was 1 error:
90
91<span class="kw">1</span>) <span class="kw">LinkDBTest</span>::testConstructLoggedIn
92<span class="kw">Missing</span> argument 2 for LinkDB::__construct(), <span class="kw">called</span> in /home/virtualtam/public_html/shaarli/tests/Link\
93<span class="kw">DBTest.php</span> on line 79 and defined
94
95<span class="kw">/home/virtualtam/public_html/shaarli/application</span>/LinkDB.php:<span class="kw">58</span>
96<span class="kw">/home/virtualtam/public_html/shaarli/tests</span>/LinkDBTest.php:<span class="kw">79</span>
97
98<span class="kw">--</span>
99
100<span class="kw">There</span> were 2 failures:
101
102<span class="kw">1</span>) <span class="kw">LinkDBTest</span>::testCheckDBNew
103<span class="kw">Failed</span> asserting that two strings are equal.
104<span class="kw">---</span> Expected
105<span class="kw">+++</span> Actual
106<span class="kw">@@</span> @@
107<span class="kw">-</span><span class="st">&#39;e3edea8ea7bb50be4bcb404df53fbb4546a7156e&#39;</span>
108<span class="kw">+</span><span class="st">&#39;85eab0c610d4f68025f6ed6e6b6b5fabd4b55834&#39;</span>
109
110<span class="kw">/home/virtualtam/public_html/shaarli/tests</span>/LinkDBTest.php:<span class="kw">121</span>
111
112<span class="kw">2</span>) <span class="kw">LinkDBTest</span>::testCheckDBLoad
113<span class="kw">Failed</span> asserting that two strings are equal.
114<span class="kw">---</span> Expected
115<span class="kw">+++</span> Actual
116<span class="kw">@@</span> @@
117<span class="kw">-</span><span class="st">&#39;e3edea8ea7bb50be4bcb404df53fbb4546a7156e&#39;</span>
118<span class="kw">+</span><span class="st">&#39;85eab0c610d4f68025f6ed6e6b6b5fabd4b55834&#39;</span>
119
120<span class="kw">/home/virtualtam/public_html/shaarli/tests</span>/LinkDBTest.php:<span class="kw">133</span>
121
122<span class="kw">FAILURES</span>!
123<span class="kw">Tests</span>: 36, Assertions: 63, Errors: 1, Failures: 2.</code></pre>
124<h4 id="test-results-and-coverage">Test results and coverage</h4>
125<p>By default, PHPUnit will run all suitable tests found under the <code>tests</code> directory.</p>
126<p>Each test has 3 possible outcomes:</p>
127<ul>
128<li><code>.</code> - success<br /></li>
129<li><code>F</code> - failure: the test was run but its results are invalid<br /></li>
130<li>the code does not behave as expected<br /></li>
131<li>dependencies to external elements: globals, session, cache...<br /></li>
132<li><code>E</code> - error: something went wrong and the tested code has crashed<br /></li>
133<li>typos in the code, or in the test code<br /></li>
134<li>dependencies to missing external elements</li>
135</ul>
136<p>If Xdebug has been installed and activated, two coverage reports will be generated:</p>
137<ul>
138<li>a summary in the console<br /></li>
139<li>a detailed HTML report with metrics for tested code<br /></li>
140<li>to open it in a web browser: <code>firefox coverage/index.html &amp;</code></li>
141</ul>
142</body>
143</html>