Chapter 13. Wireshark Tests

Table of Contents

13.1. Quick Start
13.2. Test suite structure
13.2.1. Test Coverage And Availability
13.2.2. Suites, Cases, and Tests
13.2.3. pytest fixtures
13.3. Listing And Running Tests
13.4. Adding Or Modifying Tests
13.5. External Tests
13.5.1. Custom Fixtures

The Wireshark sources include a collection of Python scripts that test the features of Wireshark, TShark, Dumpcap, and other programs that accompany Wireshark. These are located in the test directory of the Wireshark source tree.

The command line options of Wireshark and its companion command line tools are numerous. These tests help to ensure that we don’t introduce bugs as Wireshark grows and evolves.

13.1. Quick Start

The recommended steps to prepare for and run tests with a UN*X toolchain:

  • Install two Python packages, pytest: pip install pytest pytest-xdist
  • Build programs (“wireshark”, “tshark”, etc.): ninja
  • Build additional programs for the “unittests” suite: ninja test-programs
  • Run tests in the build directory: pytest

Replace ninja by make as needed.

If building with Microsoft Visual Studio the analogous steps are:

  • Install pytest Python packages: python -m pip install pytest pytest-xdist
  • Build programs: msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln
  • Build test-programs: msbuild /m /p:Configuration=RelWithDebInfo test-programs.vcxproj
  • Run tests: python -m pytest

Depending on your PATH, you may need to run the pytest module as a script from your Python interpreter, e.g, python -m pytest or python3 -m pytest instead of pytest.

The test suite will attempt to test as much as possible and skip tests when its dependencies are not satisfied. For example, packet capture tests require a Loopback interface and capture privileges. To avoid capture tests, pass the --disable-capture option.

List available tests with pytest --collectonly. Enable verbose output with pytest --verbose. For more details, see Section 13.3, “Listing And Running Tests”.

You can also run the "ninja test" target instead of invoking pytest directly. This will automatically build the test programs dependency, so it may be preferred for that reason.