Correct page on testing

This commit is contained in:
Philip Sargent 2021-12-01 20:24:34 +00:00
parent f05f280a79
commit 3a16e77bef
5 changed files with 76 additions and 52 deletions

View File

@ -146,7 +146,7 @@ you can contribute to fixing things in the <a href="todo.html">Expo <em>Systems<
If you really want to get stuck into the code you will need a <a href="../troggle/troglaptop.html">troggle software development configuration</a>.
<p>Finally, if that all sounds like too much hassle for you, were are in desparate need
of a lot more very simple <a href="../troggle/unittests.html">unit tests for troggle</a>.
of a lot more very simple <a href="../troggle/trogtests.html">tests for troggle</a>.
The more tests we have, the more confident we can be
about making big changes without breaking things. We especially need these for the input parsers
as whatever happens in the future, we are still going to need to parse the archived input files.

View File

@ -36,7 +36,7 @@
</ul>
<a href="trogdjango.html">Troggle and Django</a> - The Django web framework we use<br>
<a href="trogdjangup.html">Troggle: updating Django</a> - Upgrading troggle to use a later Django version<br>
<a href="unittests.html">Troggle unit tests</a> - test suite for programmers<br>
<a href="trogtests.html">Troggle tests</a> - test suite for programmers<br>
<a href="trogstatus.html">Troggle & expo systems - status update</a> - where we are now<br>
<br>
@ -48,7 +48,7 @@
<ul>
<li><a href="scriptsqms.html">QM (Question Mark) Scripts</a> - all five ways we do it<br>
<li><a href="scriptscurrent.html">Additional Scripts</a> - more detail<br>
<li><a href="exportjson.html">Export all.tgz</a> - export compressed survey data (Makefile)<br>
<li><a href="exporttgz.html">Export all.tgz</a> - export compressed survey data (Makefile)<br>
</ul>
<br>

View File

@ -82,7 +82,7 @@ to <a href="../computing/contribute.html#programming">get involved in the progra
</ul>
<h3>Running the test suite</h3>
<ul>
<li><a href="unittests.html">Troggle - Page tests and unit tests</a> <br>
<li><a href="trogtests.html">Troggle - Page tests and smoke tests</a> <br>
</ul>
<h3>This manual is very incomplete - notes</h3>

View File

@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Handbook Troggle - Automated Testing</title>
<link rel="stylesheet" type="text/css" href="../../css/main2.css" />
</head>
<body><style>body { background: #fff url(/images/style/bg-system.png) repeat-x 0 0 }</style>
<h2 id="tophead">CUCC Expedition Handbook</h2>
<h1>Handbook Troggle - Automated Testing</h1>
<h2>Troggle Automated Testing</h2>
<p>We have a suite of more than 70 <a href="https://en.wikipedia.org/wiki/Smoke_testing_(software)">smoke tests</a>
which are run manually by troggle programmers like this:
<pre><code> troggle$ python manage.py test -v 1</code></pre>
<p>These are 'end to end' tests which very quickly show whether something is badly broken. The tests are for two purposes only:
<ul>
<li>To check whether anything has broken when we try a new version of python, Django or a Django plugin
<li>To check that the troggle system has been installed correctly on a new machine
</ul>
<p>This is surprisingly effective. Django produces excellently detailed tracebacks when an fault happens,
which allow us to home in on the precise part of the code which has been broken by a version upgrade.
<p>We do also have a handful of unit tests which just poke data into the database and check that it can be read out again.
<p>
The test code is all in <a href="http://expo.survex.com/repositories/troggle/.git/tree/core/TESTS/"><var>troggle/core/TESTS/</var></a>.
<h4>Example test</h4>
<p>The test 'test_page_expofile' checks that a particular PDF is being served correctly by the web server
and that the resulting page is the correct length of 2,299,270 bytes:
<pre><code>
def test_page_expofile(self):
# Flat file tests.
response = self.client.get('/expofiles/documents/surveying/tunnel-loefflerCP35-only.pdf')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 2299270)
</code></pre>
<h3>Django test system</h3>
<p>This test suite uses the <a href="https://docs.djangoproject.com/en/3.2/topics/testing/">the
django test system</a>. One of the things this does
is to ensure that all the settings are imported correctly and makes it easy to specify a test as an input URL and expected
HTML output using a Django object <a href="https://docs.djangoproject.com/en/3.2/topics/testing/tools/">text client</a>.
It sets up a very fast in-memory sqlite database purely for tests.
No tests are run with the real expo database.
<h3>Troggle tests</h3>
<p>The tests can be run at a more verbose level by setting the <var>-v 3</var> flag.
<p>As yet we have no test database set up, so the in-memory database starts entirely empty. However we have 'fixtures' in
<var>troggle/core/fixtures/ </var>
which are JSON files containing dummy data which is read in before a few of the tests.
<h4>Automated testing on the server</h4>
<p>Something is stopping the test suite running on the server. We haven't fixed this yet.
<h4>How you can help</h4>
<p>We could do with a lot more unit tests which test small, specific things. If we have a lot of these it will make future re-engineering of troggle easier, as we can more confidently tackle big re-writes and still be sure that nothing is broken.
<p>We haven't got any tests which check that the <a href="trogimport.html">input parsers</a> work. None.
<p>Have a look at Wikpedia's <a href="https://en.wikipedia.org/wiki/Software_testing">review of types of software testing</a> for ideas.
<p>If you want to write some tests and are having trouble finding something which is untested, have a look at the list of
url paths in the routing system in <var>troggle/urls.py</var>
and look for types of url which do not appear in the test suite checks.
<hr />
Go on to: <a href="trogarch.html">Troggle architecture</a><br />
Return to: <a href="trogintro.html">Troggle intro</a><br />
Troggle index:
<a href="trogindex.html">Index of all troggle documents</a><br /><hr />
</body>
</html>

View File

@ -1,48 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Handbook Troggle - Unit Tests</title>
<link rel="stylesheet" type="text/css" href="../../css/main2.css" />
</head>
<body><style>body { background: #fff url(/images/style/bg-system.png) repeat-x 0 0 }</style>
<h2 id="tophead">CUCC Expedition Handbook</h2>
<h1>Handbook Troggle - Unit Tests</h1>
<h2>Troggle Unit Tests</h2>
<p>We have a small suite of tests which are run manually by troggle programmers like this:
<pre><code> troggle$ python manage.py test -v 1</code></pre>
The test code is all in <a href="http://expo.survex.com/repositories/troggle/.git/tree/core/TESTS/tests.py"><var>troggle/core/TESTS/tests.py</var></a>.
<p>The test 'test_page_expofile' checks that a particular PDF is being served correctly by the web server
and that the resulting page is the correct length of 2,299,270 bytes:
<pre><code>
def test_page_expofile(self):
# Flat file tests.
response = self.client.get('/expofiles/documents/surveying/tunnel-loefflerCP35-only.pdf')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.content), 2299270)
</code></pre>
<p>This test suite is part of <a href="https://docs.djangoproject.com/en/1.11/topics/testing/">the
django test system</a> which is a very thin layer on top of the standard python library module
<a href="https://docs.python.org/3/library/unittest.html#module-unittest">unittest</a>. One of the things this layer does
is to ensure that all the settings are imported correctly, and it sets up a very fast in-memory sqlite database purely for tests.
No tests are run with the real expo database.
<p>The tests can be run at a more verbose level by setting the <var>-v 3</var> flag.
<p>As yet we have no test database set up, so the in-memory database is entirely empty. However we have 'fixtures' in
<var>troggle/core/fixtures/ </var>
which are JSON files containing dummy data which is used in the more complex tests.
<p>If you want to write some tests and are having trouble finding something which is untested, have a look at the list of
url paths in the routing system in <var>troggle/urls.py</var>
and look for types of url which do not appear in the test suite checks.
<hr />
Go on to: <a href="trogarch.html">Troggle architecture</a><br />
Return to: <a href="trogintro.html">Troggle intro</a><br />
Troggle index:
<a href="trogindex.html">Index of all troggle documents</a><br /><hr />
</body>
</html>