Engineering: Computer Security.
Semester: 05.
Python Programming
Year: 2025-2026 By Dr. HANAFI [Link]
Course Content
▪ Introduction about the course.
▪ Part 1: Beginning Python
▪ Part 2: Advanced Python
▪ Part 3: Python Workbook
▪ Part 4: Generating Python Bindings for XML
UNIT TESTS
Unit Tests
Unit Testing is the first level of software testing where the smallest testable parts of
software are tested. This is used to validate that each software unit performs as designed.
Python Unittest is a built-in testing framework that provides a set of tools for testing our
code’s functionality in a more systematic and organized manner.
With unittest framework, we can create test cases, fixtures, and suites to verify if our
code behaves as expected.
It allows us to write test methods within classes that check different aspects of our code
such as input, output, and edge cases.
It also supports test discovery making it easy for us to automate test execution across our
project.
Unit Tests
Assert Methods
unittest has lots of methods to assert on the values, types, and existence of variables.
Below are some of the methods that are commonly used to write assertions.
Unit Tests
Python Unittest Example
Unit Tests
Outcomes Possible in Unit Testing
✓ OK–This means that all the tests are passed.
✓ FAIL– This means that the test did not pass and an Assertion Error exception is raised.
✓ ERROR–This means that the test raises an exception other than AssertionError.
Unit Tests
Q&A