User Tools

Site Tools


automation:test-the-network

This is an old revision of the document!


hierarchy typically looks like:

  • Unit testing (atomic level) - individual functions/methods. (Module testing often gets lumped into either “unit testing” (for simple modules) or “component testing” (for complex modules))
  • Component testing - groups of related units working together
  • Integration testing - multiple components interacting
  • System testing - entire application

OPTIONS

Classic1: Unittest / **pytest** libraries

TODO

__Modern1: PyATS__

Assertions
  • Definition: Statements used in tests to verify that a specific condition holds true.
  • Usage: Typically done using Python's built-in
    assert

    statement.

  • Example:
    assert interface.status == "up"
 
  • Purpose: To validate correctness during test execution; a failed assertion marks the test as failed.

Markers
  • Definition: Annotations to add metadata to test functions or classes.
  • Usage: Used to categorize, skip, or parametrize tests.
  • Examples:
    • @pytest.mark.sanity

      (categorization)

    • @pytest.mark.skip(reason="Not implemented")

      (skipping)

    • pyATS-specific:
      @aetest.loop

      ,

      @aetest.setup

      ,

      @aetest.cleanup
  • Purpose: Control test behavior, grouping, and execution.

Fixtures
  • Definition: Reusable setup/teardown functions for tests.
  • Usage: Implemented with
    @pytest.fixture

    .

  • Example:
    @pytest.fixture
    def test_device():
        device = connect_to_device("router1")
        yield device
        device.disconnect()
 
  • Purpose: Manage test environments and dependencies, ensuring isolation and reproducibility.

Parametrization
  • Definition: Technique to run the same test with different sets of parameters.
  • Usage: Implemented with
    @pytest.mark.parametrize

    .

  • Example:
    @pytest.mark.parametrize("ip", ["8.8.8.8", "1.1.1.1"])
    def test_ping(ip):
        assert ping(ip)
 
  • Purpose: Increase coverage by testing with multiple data sets.

Other Relevant Concepts
  • Testcase/Testscript:
    • A testcase is a Python class, often subclassing
      aetest.Testcase

      , containing test sections.

    • A testscript is a file containing one or more testcases.
  • Sections:
    • Special methods within a testcase, such as
      setup

      ,

      test

      , and

      cleanup

      .

  • Testbed:
    • A YAML or Python file describing devices and connections used in tests.
  • Loggers:
    • Used for reporting test steps and results (
      log

      object).

  • aetest:
    • Core pyATS test harness module for organizing and running tests.

Examples
automation/test-the-network.1751784726.txt.gz · Last modified: by jotasandoku