Pelmen323 / Kaiserreich_Autotests

Python tests for Kaiserreich
MIT License
1 stars 0 forks source link
hoi4mod jenkins pytest python test-automation testing

Pytest Tests for Kaiserreich

Repository for .py tests for Kaiserreich with the possibility to set up Jenkins as a runner. It can be used 'as is' for Kaiserreich users, they only need to pass their system username in which doc folder the project is located and the name of the mod folder (see screenshots lower). For other HOI4 projects, it can be used as well but no support is provided.

The general idea of the project is to automate the scenarios testing that is almost impossible to verify otherwise (they can be checked manually via CWTools in some cases, but my solution benefits from all automation perks - it is never tired, fast and provides almost instant feedback). Tests are NOT running the game, instead, they parse and analyze the codebase. Repository is constantly updated - tests are mostly created upon finding bugs.

In-built multithreading support and high-performance optimization, current full runtime - around 3 minutes with 6 cores utilised.

Requirements - Python installation with pytest and pytest-xdist plugins.

Currently included tests

90+ tests, including:

Advisors tests

Characters tests

Cosmetic tags tests:

Character flags tests:

Country flags tests:

Decisions tests:

Events tests

Event targets tests

Global flags tests:

Ideas tests:

Localization tests

OOB files tests:

Opinion modifiers tests:

Performance tests

Scripted triggers and effects tests:

State flags tests:

Syntax tests:

Project development timeline on the Jenkins graph

Screenshot (2159)

Pytest instructions

It allows to run test locally, all you need is python installation and installed 'pytest' and 'pytest-xdist' plugins

  1. Create venv with pytest installed - 'pip install pytest' or 'pipenv install pytest' if you use pipenv
  2. Install pytest-xdist - 'pip install pytest-xdist' or 'pipenv install pytest-xdist' if you use pipenv
  3. Clone repository with tests
  4. Change directory to repository directory
  5. Run:

    pytest -v -s --tb=short "--username=xxx" "--mod_name=xxx" -n 6"

    in console, replace username with your system username and mod_name with mod folder name, -n - number of your CPU cores Screenshot (1959)

Pytest-Jenkins instructions

It allows to run tests automatically based on specific triggers

  1. Create a Python Virtual Environment, install Pytest via 'pip install pytest' or 'pipenv install pytest' if you use pipenv, install 'pytest-xdist' - 'pip install pytest-xdist' or 'pipenv install pytest-xdist' if you use pipenv

  2. Install Jenkins

  3. Install Python Plugin and ShiningPanda Plugin Jenkins plugins: Screenshot (1782)

  4. Provide Git and Python paths in "Manage Jenkins/Global Tool Configuration/" (For Python - provide path to your virtual environment python.exe file) Screenshot (1783)

  5. Create a new Job (Freestyle project)

  6. Configure the job

    • GitHub repository, branch - main
    • Build action - Custom Python Builder, path to your venv (not to exe), nature - Shell, command:

      pytest -v -s --tb=short "--username=xxx" "--mod_name=xxx" -n 6 --junitxml TestResults.xml

      (replace username with your system username and mod_name with mod folder name, -n - number of your CPU cores) Screenshot (1961)

    • Post-Build Actions - Publish Junit test result report, test report xmls - *.xml Screenshot (1962)
  7. Setup the Build Triggers (or you can trigger the job manually)

  8. Save the job

Diagram