zeek/testing/btest
Johanna Amann cb47b37215 Be more liberal with whitespaces for ip-addresses, subnets, etc.
This change ignores leading/trailing whitespaces for a couple of
data-types (bool, port, subnet, addr) and just parses them as if the
whitespace was not present.
2019-02-19 15:06:06 -08:00
..
Baseline Be more liberal with whitespaces for ip-addresses, subnets, etc. 2019-02-19 15:06:06 -08:00
bifs Merge branch 'master' of https://github.com/ZekeMedley/zeek 2019-02-15 17:51:29 -06:00
broker A few more updates to the digest functions. 2019-01-24 10:44:28 -08:00
core Merge remote-tracking branch 'origin/topic/jsiwek/gh-211' 2019-02-07 10:33:52 -06:00
coverage Skip autogenerated doc coverage test for Travis pull requests 2019-02-15 17:53:53 -06:00
doc Remove Sphinx btest integrations and tests 2018-12-14 16:32:35 -06:00
Files
language add rstrip tests 2019-02-13 23:51:27 -08:00
plugins Bro plugins should support a patch version (x.y.z) 2018-09-30 20:30:22 -04:00
scripts Be more liberal with whitespaces for ip-addresses, subnets, etc. 2019-02-19 15:06:06 -08:00
signatures Fix segmentation fault on eval condition with no return value. 2017-09-19 09:23:09 -07:00
Traces Added ERSPAN III testing 2019-01-24 14:05:13 +00:00
.gitignore
btest.cfg GH-211: improve consistency of how scripting errors are handled 2019-01-30 11:20:09 -06:00
Makefile Add code coverage for bro source files after btest test suite 2018-06-22 14:27:46 -07:00
random.seed Remove the -K/-J options for setting keys. 2016-07-13 16:57:53 -07:00
README Update github/download links 2018-12-07 16:36:51 -06:00

This a test suite of small "unit tests" that verify individual pieces of Bro
functionality.  They all utilize BTest, a simple framework/driver for
writing unit tests.  More information about BTest can be found at
https://github.com/zeek/btest

The test suite's BTest configuration is handled through the
``btest.cfg`` file.  Of particular interest is the "TestDirs" settings,
which specifies which directories BTest will recursively search for
test files.

Significant Subdirectories
==========================

* Baseline/
	Validated baselines for comparison against the output of each
	test on future runs. If the new output differs from the Baseline
	output, then the test fails.

* Traces/
	Packet captures utilized by the various BTest tests.

* scripts/
	This hierarchy of tests emulates the hierarchy of the Bro scripts/
	directory.

* coverage/
	This collection of tests relates to checking whether we're covering
	everything we want to in terms of tests, documentation, and which
	scripts get loaded in different Bro configurations.  These tests are
	more prone to fail as new Bro scripts are developed and added to the
	distribution -- checking the individual test's comments is the best
	place to check for more details on what exactly the test is checking
	and hints on how to fix it when it fails.

Running Tests
=============

Either use the ``make all`` or ``make brief`` ``Makefile`` targets, or
run ``btest`` directly with desired options/arguments.  Examples:

* btest <no arguments>
	If you simply execute btest in this directory with no arguments,
	then all directories listed as "TestDirs" in btest.cfg will be
	searched recursively for test files.


* btest <btest options> test_directory
	You can specify a directory on the command line to run just the
	tests contained in that directory. This is useful if you wish to
	run all of a given type of test, without running all the tests
	there are. For example, "btest scripts" will run all of the Bro
	script unit tests.


* btest <btest options> test_directory/test_file
	You can specify a single test file to run just that test. This
	is useful when testing a single failing test or when developing
	a new test.

Adding Tests
=============

See either the `BTest documentation
<https://github.com/zeek/btest>`_ or the existing unit
tests for examples of what they actually look like.  The essential
components of a new test include:

* A test file in one of the subdirectories listed in the ``TestDirs``
  of the ``btest.cfg`` file.

* If the unit test requires a known-good baseline output against which
  future tests will be compared (via ``btest-diff``), then that baseline
  output will need to live in the ``Baseline`` directory.  Manually
  adding that is possible, but it's easier to just use the ``-u`` or
  ``-U`` options of ``btest`` to do it for you (using ``btest -d`` on a
  test for which no baseline exists will show you the output so it can
  be verified first before adding/updating the baseline output).

If you create a new top-level testing directory for collecting related
tests, then you'll need to add it to the list of ``TestDirs`` in
``btest.cfg``. Do this only if your test really doesn't fit logically in
any of the extant directories.