Introduction
CI integration helps run tests automatically every time code changes. This keeps the software safe and working well all the time.
CI integration helps run tests automatically every time code changes. This keeps the software safe and working well all the time.
def test_example(): # test steps here assert condition # In CI, this test runs automatically on code push
def test_title(driver): driver.get('https://example.com') assert 'Example Domain' in driver.title
# In CI config file (example for GitHub Actions): # runs tests on every push name: Python Tests on: [push] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.12' - name: Install dependencies run: pip install selenium pytest - name: Run tests run: pytest
This simple Selenium test opens a website and checks its title. It uses pytest for easy automation. In CI, this test runs automatically on every code change.
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import pytest @pytest.fixture def driver(): options = Options() options.add_argument('--headless') service = Service() driver = webdriver.Chrome(service=service, options=options) yield driver driver.quit() def test_example_domain_title(driver): driver.get('https://example.com') assert 'Example Domain' in driver.title # This test can be run automatically in CI to check the website title.
Make sure tests are fast and stable for smooth CI runs.
Use headless browsers in CI to avoid opening windows.
Keep test failures clear to fix problems quickly.
CI integration runs tests automatically on code changes.
This helps catch bugs early and saves manual effort.
Automated tests in CI keep software reliable and ready to release.
pytest tests/ to execute tests automatically.pytest tests/ command in the CI script -> Option Dsteps:
- name: Run tests
run: pytest tests/Pass the test and this pattern moves unknown