Webunit test client
Webunit is a command line client for automated web application tests.
- PHP >= 7.1
$ composer require michaelhall/webunit
webunit client requires a file in text format, containing the tests to run. Pass the name of this file as a command line parameter:
$ webunit testfile
The tests in the test file consists of one or more test cases. Every test case starts with a command. The most basic test case is just a command, e.g.
This test will be successful if the Url
https://example.org/ is functional and does not return an error or redirect status code. Otherwise the test will fail.
A test case can also contain specific assertions:
get https://example.org/ assert-contains Example
Comments and whitespaces can be used to format the test file:
# This is a comment. get https://example.org/ assert-contains Example # Another test case. get https://example.org/foobar assert-status-code 404
Some of the assertions can be modified with modifier characters:
get https://example.org/ # The "!" modifier negates the assertion. # This assertion will pass if the returned status code is not 404 assert-status-code! 404 # The "^" modifier makes the assertion case insensitive. # This assertion will pass if result contains "Example", "EXAMPLE", "eXaMpLe" etc. assert-contains^ example # The "~" modifier evaluates the assertion as a regular expression. # This assertion will pass if result contains "Example" or "example". assert-contains~ [Ee]xample # Modifiers can be combined. # This assertion will fail if result contains "FooBar", "foobar" etc. assert-contains!^ foobar
Fetches a Url via a
Asserts that the content of the result contains the specified content. Allowed modifiers are
Asserts that the content of the result is empty. Allowed modifier is
Asserts that the content of the result is the same as the specified content. Allowed modifiers are
Asserts that the result contains a header with the specified name and an optional value. Allowed modifiers are
assert-header Location assert-header Location: https://example.com/
Note: The header name is always case insensitive.
Asserts that the status code of the result is the same as the specified status code. Allowed modifier is
Note: This assert must be present for test a to pass if the result has a status code other than 200-299.