1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
.. _testing:
Testing Overview
================
ws4py is a Python library which means it can be tested in various fashion:
- unit testing
- functional testing
- load testing
Though all of them are of useful, ws4py mostly relies on functional testing.
Unit Testing
------------
Unit testing solves complex issues in a simple fashion:
- Micro-validation of classes and functions
- Ensure non-regression after modifications
- Critique the design as early as possible for minimum impact
Too often, developers focus solely on the first two and fail
to realise how much feedback they can get by writing a simple unit tests.
Usually starting writing unit tests can take time because your
code is too tightly coupled with itself or external dependencies. This
should not the case, most of the time anyway.
So make sure to reflect on your code design whenever you have difficulties
setting up proper unit tests.
.. note::
Unfortunately, for now ws4py has a rather shallow coverage as it relies
more on the functional testing to ensure the package is sane. I hope
to change this in the future.
Framework
^^^^^^^^^
ws4py uses the Python built-in :mod:`unittest` module. Make sure you read
its extensive documentation.
Execution
^^^^^^^^^
Test execution can be done as follow:
.. code-block:: console
cd test
python -m unittest discover # execute all tests in the current directory
Tests can obviously be executed via nose, unittest2 or py.test if you prefer.
Functional Testing
------------------
ws4py relies heavily on the extensive `testing suite <http://autobahn.ws/testsuite>`_
provided by the `Autobahn <http://autobahn.ws/>`_ project.
The server test suite is used by many other WebSocket implementation out there
and provides a great way to validate interopability so it must be executed
before each release to the least. Please refer to the :ref:`requirements`
page to install the test suite.
Execution
^^^^^^^^^
- Start the CherryPy server with PyPy 1.9
.. code-block:: console
pypy test/autobahn_test_servers.py --run-cherrypy-server-pypy
- Start the CherryPy server with Python 3.2 and/or 3.3 if you can.
.. code-block:: console
python3 test/autobahn_test_servers.py --run-cherrypy-server-py3k
- Start all servers with Python 2.7
.. code-block:: console
python2 test/autobahn_test_servers.py --run-all
- Finally, execute the test suite as follow:
.. code-block:: console
wstest -m fuzzingclient -s test/fuzzingclient.json
The whole test suite will take a while to complete so be patient.
|