Skip to content

Testing our collection

Mariana Villar edited this page Jan 19, 2023 · 3 revisions

As testing framework, we have implemented:

  • Unit test for modules
  • Playbooks to test the roles and module's functionality.

Unit test for modules - test_queue_manager.py

The class TestQueueManager tests if the state of a queue manager has been changed after calling the queue_manager.py module. It uses the module's attribute unit_test as a flag (unit_test: True) to indicate that the module is being called in a unit test. Our tests checks if a queue manager has been:

  • Created - state: present
  • Started - state: running
  • Deleted - state: absent

Please note this does not test the performance of our collection.

Example of unit testing of module

Note: Exeption classes AnsibleExitJson and AnsibleFailJson should be set. See test_queue_manager.py for reference.

def test_delete_qm(self):
    set_module_args({
        'qmname': 'qm1',
        'state': 'absent',
        'description': 'testing',
        'unit_test': True
    })
    with self.assertRaises(AnsibleExitJson) as result:
        queue_manager.main()
    self.assertEquals(result.exception.args[0]['state'], 'absent')

Playbook tests

These playbooks test the functionality and performance of the roles and the queue_manager module in ansible plays.

To run the test playbooks first:

  1. make sure you are in the right directory
    $ cd tests/playbooks
  2. export the modules to your ansible library
    $ export ANSIBLE_LIBRARY=<PATH-TO>/ansible_mq/ansible_collections/ibm/ibmmq/library
    • NOTE : change <PATH-TO> to your local directory path:
  3. run all test playbooks with main.py

To add playbook tests:

Use the ansible attribute fail_when: False when calling the module in the ansible playbook but do not use this on assert statements. This will allow the other tests to run along with the clean up, indicating the failed test.