Go to PolySwarm

Unit Testing

All commands listed here assume:

  1. your current working directory is the root directory of your participant and
  2. that your participant is built on the PolySwarm participant template participant-template.

Build Your Participant's Docker Image

You'll need to build a Docker image of your participant for unit and integration testing.

For Linux-based participants:

$ docker build -t `basename ${PWD}` -f docker/Dockerfile .

For Windows-based participants:

PS > docker build -t (Get-Item (get-location)).Basename -f .\docker\Dockerfile .

This will produce a Docker image tagged with the name of the directory, e.g. microengine-eicar.

Run Unit Tests

Supplied unit tests are quite limited and only support microengines. Running unit tests on ambassadors and arbiters will fail unless you supply unit test functions.

Unit testing logic is housed in the tests/ folder. Customize the script(s) there to implement your unit tests.

For Linux-based participants:

$ docker-compose -f docker/test-unit.yml up

For Windows-based participants:

PS > docker run --isolation=process <YOUR PARTICIPANT'S DOCKER IMAGE> pytest -s

Example unit test output ensuring that an EICAR-detecting microengine actually detects EICAR (Windows-based output will vary slightly):

Creating docker_test_testing5_1_1f70f81dfe58 ... done
Attaching to docker_test_testing5_1_9c0763ba3fca
test_testing5_1_9c0763ba3fca | ============================= test session starts ==============================
test_testing5_1_9c0763ba3fca | platform linux -- Python 3.6.8, pytest-3.9.2, py-1.8.0, pluggy-0.12.0
test_testing5_1_9c0763ba3fca | hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/usr/src/app/.hypothesis/examples')
test_testing5_1_9c0763ba3fca | rootdir: /usr/src/app, inifile:
test_testing5_1_9c0763ba3fca | plugins: asyncio-0.9.0, hypothesis-3.82.1, timeout-1.3.2, cov-2.6.0
test_testing5_1_9c0763ba3fca | collected 1 item
test_testing5_1_9c0763ba3fca |
test_testing5_1_9c0763ba3fca | tests/test_testing5.py .
test_testing5_1_9c0763ba3fca |
test_testing5_1_9c0763ba3fca | =============================== warnings summary ===============================
test_testing5_1_9c0763ba3fca | /usr/local/lib/python3.6/site-packages/eth_utils/applicators.py:32: DeprecationWarning: combine_argument_formatters(formatter1, formatter2)([item1, item2])has been deprecated and will be removed in a subsequent major version release of the eth-utils library. Update your calls to use apply_formatters_to_sequence([formatter1, formatter2], [item1, item2]) instead.
test_testing5_1_9c0763ba3fca |   "combine_argument_formatters(formatter1, formatter2)([item1, item2])"
test_testing5_1_9c0763ba3fca |
test_testing5_1_9c0763ba3fca | -- Docs: https://docs.pytest.org/en/latest/warnings.html
test_testing5_1_9c0763ba3fca | ===================== 1 passed, 1 warnings in 0.90 seconds =====================
docker_test_testing5_1_9c0763ba3fca exited with code 0

Next Steps

With unit tests passing, it's time to move onto Integration Testing.