1# Test suite
2
3bashnapi comes with a comprehensive test suite and test environment. In order
4to use it you'll need [Docker](https://www.docker.com).
5
6## Containers
7
8In order to support the environment you'll need to build images for the
9_Docker_ containers. The following _Docker_ files have been provided:
10
11- `Dockerfile-napitester` - an image containing all the dependencies and
12libraries for unit testing.
13
14- `Dockerfile-napiserver` - an image running
15[Pretenders](https://github.com/pretenders/pretenders) used for integration
16testing and acting as [napiprojekt.pl](http://napiprojekt.pl) mock.
17
18- `Dockerfile-napiclient` - this image is extending a napi image from the main
19directory - (you'll have to build it first), and is used for integration
20testing. It contains an installation of napi.sh along with integration tests
21dependencies.
22
23## Preparations
24
25Assuming that the current working directory is the root of the project, build
26the napi _Docker_ image:
27
28    docker build -t napi .
29
30Once that's done, proceed to the `tests` directory to build the rest of the
31images:
32
33    cd tests
34    docker-compose build
35
36If the last step was successful, all the required images have been built and
37are ready to use.
38
39## Unit tests
40
41To run all unit tests, simply invoke
42
43    ./run_unit_tests.sh
44
45in the `tests` directory. It's possible to run a selected test only as well.
46Just provide the file name:
47
48    ./run_unit_tests.sh libnapi_http_test.sh
49
50Each unit tests execution generates coverage report which can be found in
51`tests/converage` directory. Navigate your browser there to get more details.
52
53## Integration tests
54
55Integration test suite will start a dedicated container running python
56pretenders to mock napiprojekt.pl. The test will run in a separate container. To run the tests just invoke:
57
58    ./run_integration_tests.sh
59
60If you change any of napi code, these changes will have to be incorporated into
61Docker container as well, for the test suite to pick it up. In order to quickly
62do that without rebuilding the images, just invoke:
63
64    ./run_integration_tests.sh -u
65
66### Running integration tests manually
67
68It's possible to execute only selected test fixture:
69
70    docker-compose run --rm napiclient python -m unittest integration_tests.test_formats.FormatsConversionTest
71
72... or a test case:
73
74    docker-compose run --rm napiclient python -m unittest integration_tests.test_formats.FormatsConversionTest.test_ifSubotageDetectsFormatsCorrectly
75
76
77In order to increase verbosity of the test suite, one can define an
78environmental variable: `NAPI_INTEGRATION_TESTS_LOGLEVEL=1`. When run manually
79this can be done with docker like so:
80
81    docker-compose run --rm -e NAPI_INTEGRATION_TESTS_LOGLEVEL=1 napiclient python -m unittest integration_tests.test_formats.FormatsConversionTest.test_ifSubotageDetectsFormatsCorrectly
82
83The integration tests suite contains some long running tests which are skipped
84by default, as the total execution time may be longer than an hour. In order to
85enable them, an environment variable `NAPI_INTEGRATION_TESTS_LONG_ENABLED=1`
86should be defined. When ran manually this can be done exactly the same way as
87in the previous example:
88
89    docker-compose run --rm -e NAPI_INTEGRATION_TESTS_LOGLEVEL=1 -e NAPI_INTEGRATION_TESTS_LONG_ENABLED=1 napiclient python -m unittest integration_tests.test_formats.FormatsConversionTest.test_ifSubotageDetectsFormatsCorrectly
90