- Docker and Docker Compose: Ensure Docker is installed and the Docker Daemon is running. You can download it here: Docker Desktop for Windows or install it via your package manager on Linux. You can find further information on the official documentation.
- Python: A version >=3.12 is required for this project
- pip: installation docs
- Clone the repository into a folder of your choice
git clone https://github.com/necodeIT/moodle-unit-tests.git && cd moodle-unit-tests- Build the Python package with:
pip install -e .After successfully building the project the cli tool is now installed on your system. You can run it with the command mut.
NOTICE: Currently the cli tool only works inside the moodle-unit-tests folder
Before running a Docker instance select the version with
NOTICE: This method is not fully implemented, use the second one for now
mut moodle initor specify it directly in the command
mut moodle init <version>Once the version has been set you can start the Moodle instance with
mut moodle run\
NOTICE: If the mariadb container is not starting properly: Do some permission stuff for the MariaDB container
After running the moodle containers for the first time the mariadb container will fail to start properly. Fix this with the following commands and start the containers again. For details: bitnami/containers#23841
useradd -u 1001 mariadb-bitnami
chown -R mariadb-bitnami:mariadb-bitnami ./docker/server/.moodle/mariadbOnce Moodle is up and running you can populate the database with data that is necessary for your tests (f.e. adding users or creating courses). To save the current state of the database as a baseline use this command:
mut baseline createThe saved database state will be restored before every test. The baseline can also be manually restored with:
mut baseline restoreTo create a Python unit test run:
mut test create <test_name> When creating a new test a new directory will be created in the tests/TESTNAME. In this directory there is a structured Python file where you can start writing your unit tests.
To run a test use:
mut test run <test_name>The results are saved in a markdown
If you encounter any issues:
-
Windows: Ensure Docker Desktop is running and WSL 2 is enabled (if using WSL).
-
Linux: Verify Docker and Docker Compose permissions. You may need to add your user to the
dockergroup to run Docker withoutsudo:sudo usermod -aG docker $USER