pubsubclient/tests/README.md

94 lines
2.8 KiB
Markdown
Raw Normal View History

2014-02-08 23:41:27 +00:00
# Arduino Client for MQTT Test Suite
2012-11-11 14:50:11 +00:00
This is a regression test suite for the `PubSubClient` library.
2014-02-08 23:41:27 +00:00
There are two parts:
- Tests that can be compiled and run on any machine
- Tests that build the example sketches using the Arduino IDE
2012-11-11 15:09:23 +00:00
It is a work-in-progress and is subject to complete refactoring as the whim takes
me.
2014-02-08 23:41:27 +00:00
## Local tests
2014-02-08 23:45:27 +00:00
These are a set of executables that can be run to test specific areas of functionality.
They do not require a real Arduino to be attached, nor the use of the Arduino IDE.
The tests include a set of mock files to stub out the parts of the Arduino environment the library
depends on.
2014-02-08 23:41:27 +00:00
### Dependencies
- g++
### Running
Build the tests using the provided `Makefile`:
$ make
This will create a set of executables in `./bin/`. Run each of these executables to test the corresponding functionality.
*Note:* the `connect_spec` and `keepalive_spec` tests involve testing keepalive timers so naturally take a few minutes to run through.
## Arduino tests
*Note:* INO Tool doesn't currently play nicely with Arduino 1.5. This has broken this test suite.
2012-11-11 14:50:11 +00:00
Without a suitable arduino plugged in, the test suite will only check the
example sketches compile cleanly against the library.
With an arduino plugged in, each sketch that has a corresponding python
test case is built, uploaded and then the tests run.
2014-02-08 23:41:27 +00:00
### Dependencies
2012-11-11 14:50:11 +00:00
- Python 2.7+
- [INO Tool](http://inotool.org/) - this provides command-line build/upload of Arduino sketches
2014-02-08 23:41:27 +00:00
### Running
2012-11-11 14:50:11 +00:00
2012-11-11 15:09:23 +00:00
The test suite _does not_ run an MQTT server - it is assumed to be running already.
2012-11-11 14:50:11 +00:00
2012-11-11 15:13:02 +00:00
$ python testsuite.py
2012-11-11 14:50:11 +00:00
2012-11-11 15:09:23 +00:00
A summary of activity is printed to the console. More comprehensive logs are written
to the `logs` directory.
2014-02-08 23:41:27 +00:00
### What it does
2012-11-11 14:50:11 +00:00
2012-11-11 15:13:02 +00:00
For each sketch in the library's `examples` directory, e.g. `mqtt_basic.ino`, the suite looks for a matching test case
`testcases/mqtt_basic.py`.
2012-11-11 14:50:11 +00:00
The test case must follow these conventions:
- sub-class `unittest.TestCase`
- provide the class methods `setUpClass` and `tearDownClass` (TODO: make this optional)
2012-11-11 15:05:27 +00:00
- all test method names begin with `test_`
2012-11-11 14:50:11 +00:00
The suite will call the `setUpClass` method _before_ uploading the sketch. This
2012-11-11 15:05:27 +00:00
allows any test setup to be performed before the sketch runs - such as connecting
2012-11-11 14:50:11 +00:00
a client and subscribing to topics.
2014-02-08 23:41:27 +00:00
### Settings
2012-11-11 14:50:11 +00:00
The file `testcases/settings.py` is used to config the test environment.
2012-11-11 15:13:02 +00:00
- `server_ip` - the IP address of the broker the client should connect to (the broker port is assumed to be 1883).
- `arduino_ip` - the IP address the arduino should use (when not testing DHCP).
2012-11-11 14:50:11 +00:00
Before each sketch is compiled, these values are automatically substituted in. To
2012-11-11 15:05:27 +00:00
do this, the suite looks for lines that _start_ with the following:
2012-11-11 14:50:11 +00:00
byte server[] = {
byte ip[] = {
2012-11-11 15:05:27 +00:00
and replaces them with the appropriate values.
2012-11-11 14:50:11 +00:00
2012-11-11 14:17:50 +00:00