wireshark/test
Peter Wu 54d7e96a72 test: make it possible to use pytest-style test fixtures
Currently all binaries must be available or no tests will be executed.
This is inconvenient if you just want to test a single binary (e.g.
text2pcap) without having to build epan. The problem is essentially that
tests lack dependency annotations.

To solve this problem, add the required dependencies as parameters to
each test (so-called 'fixtures' in pytest). Skip a test if a binary
(such as tshark) is unavailable. As a demonstration, suite_dissection.py
is converted. Over time, tests should no longer depend on config.py due
to explicit dependencies fixtures (listed in fixtures_ws.py).

Since the unittest module does not support such dependency injections,
create a small glue for use with pytest and an (incomplete) emulation
layer for use with test.py.

Tested with pytest 3.8.2 + Python 3.7.0 and pytest 3.0.3 + Python 3.4.3.
Python 2.7 is not supported and will fail. Test commands:

    ~/wireshark/test/test.py -p ~/build/run
    WS_BIN_PATH=~/build/run pytest ~/wireshark/test -ra

Change-Id: I6dc8c28f5c8b7bbc8f4c04838e9bf085cd22eb0b
Ping-Bug: 14949
Reviewed-on: https://code.wireshark.org/review/30220
Tested-by: Petri Dish Buildbot
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-09 05:03:12 +00:00
..
baseline Test: Add fileformats and I/O. 2018-04-27 19:52:04 +00:00
captures test: make 'double' tests rely on icmp instead of ntp. 2018-10-25 04:09:44 +00:00
config ssl,http: rename http-over-ssl to http-over-tls 2016-09-04 13:18:54 +00:00
keys KNX-IP: new KNXnet/IP dissector 2018-10-16 09:03:43 +00:00
lua lua: add support for ethernet addresses to the Address class 2018-10-18 07:51:36 +00:00
suite_dfilter test: make 'double' tests rely on icmp instead of ntp. 2018-10-25 04:09:44 +00:00
README.test Test: Remove the Bash test scripts. 2018-05-02 04:09:26 +00:00
config.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
conftest.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
fixtures.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
fixtures_ws.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
hosts.custom Continue to remove $Id$ from top of file 2014-03-31 18:48:06 +00:00
hosts.global Continue to remove $Id$ from top of file 2014-03-31 18:48:06 +00:00
hosts.personal Continue to remove $Id$ from top of file 2014-03-31 18:48:06 +00:00
pytest.ini Tests: add minimal pytest support 2018-07-17 09:04:01 +00:00
subprocesstest.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
suite_capture.py Test: Consolidate our environments. 2018-05-22 16:34:03 +00:00
suite_clopts.py test: reduce further influence from the environment 2018-10-12 18:55:04 +00:00
suite_decryption.py test: drop Python 2 compatibility, use more Python 3 features 2018-11-08 16:36:35 +00:00
suite_dissection.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
suite_fileformats.py Test: Add fileformats and I/O. 2018-04-27 19:52:04 +00:00
suite_follow.py tests: add regression tests for Follow TCP Stream 2018-07-06 12:11:09 +00:00
suite_io.py Test: Add fileformats and I/O. 2018-04-27 19:52:04 +00:00
suite_mergecap.py test: fix DeprecationWarning: invalid escape sequence 2018-10-12 18:53:21 +00:00
suite_nameres.py test: add test for resolved addresses 2018-05-12 06:29:55 +00:00
suite_sharkd.py test: drop Python 2 compatibility, use more Python 3 features 2018-11-08 16:36:35 +00:00
suite_text2pcap.py text2pcap: Fix IPv6 checksum 2018-10-31 02:45:50 +00:00
suite_unittests.py Test+CMake: Make our test grouping more fine-grained. 2018-06-18 19:36:26 +00:00
suite_wslua.py Test: Add wslua. 2018-05-02 00:35:20 +00:00
test.py test: make it possible to use pytest-style test fixtures 2018-11-09 05:03:12 +00:00
util_dump_dhcp_pcap.py test: drop Python 2 compatibility, use more Python 3 features 2018-11-08 16:36:35 +00:00

README.test

Wireshark Tests

The main testing script is `test.py`. It will attempt to test as much as
possible by default, including packet capture. This means that you will
probably either have to supply a capture interface (`--capture-interface
<interface>`) or disable capture tests (`--disable-capture`). You must
also build the test-programs target in order for the unittests suite to
pass.

To run all tests from CMake do the following:
- Pass `-DTEST_EXTRA_ARGS=--disable-capture` or
  `-DTEST_EXTRA_ARGS=--capture-interface=<interface>`
  as needed for your system.
- Build the “test” target or run ctest, e.g. `ctest --force-new-ctest-process -j 4 --verbose`.

To run all tests directly, run `test.py -p
/path/to/wireshark-build/run-directory <capture args>`.

To see a list of all options, run `test.py -h` or `test.py --help`.

To see a list of all tests, run `test.py -l`.

See the “Wireshark Tests” chapter of the Developer's Guide for details.