Selenium with Python Tutorial 31-Python UnitTest Framework Methods

Share

Summary

This video explains the different keywords and methods available in the Python unit test framework, including `setup`, `teardown`, `setupClass`, `teardownClass`, `setupModule`, and `teardownModule`. It demonstrates their practical application and execution order within test cases.

Highlights

Introduction to Unit Test Framework Keywords
00:00:00

The video introduces key keywords in the Python unit test framework: setup, teardown, setupClass, teardownClass, setupModule, and teardownModule. It aims to explain how to use them practically.

Understanding setup and teardown Methods
00:00:24

The `setup` method executes before every test method within a class, while the `teardown` method executes after every test method. This means they run multiple times, once for each test method.

Practical Demonstration of setup and teardown
00:02:19

A practical example in PyCharm demonstrates the use of `setup` and `teardown`. Four test methods are created, and `setup` is used to simulate a 'login' action before each test, and `teardown` simulates a 'logout' after each test. The output confirms that 'login' and 'logout' statements are printed before and after every individual test.

Understanding setupClass and teardownClass Methods
00:09:31

The `setupClass` method executes only once before all test methods in a class start, and `teardownClass` executes only once after all test methods in the class have completed. This contrasts with `setup` and `teardown` which run for every test method.

Practical Demonstration of setupClass and teardownClass
00:11:00

The video adds `setupClass` to open an application once before all tests and `teardownClass` to close the application once after all tests. The execution output shows 'opening application' at the very beginning and 'closing application' at the very end, confirming their single execution per class.

Understanding setupModule and teardownModule
00:14:24

The `setupModule` and `teardownModule` methods execute once at the module level. `setupModule` runs before any class or method in the module, and `teardownModule` runs after everything in the module is complete. These are defined outside of any class.

Execution Hierarchy of all Methods
00:15:45

The video concludes by illustrating the complete execution hierarchy: `setupModule` (once for the module), `setupClass` (once per class), `setup` (before every test method), actual test methods, `teardown` (after every test method), `teardownClass` (once per class), and finally `teardownModule` (once for the module).

Recently Summarized Articles

Loading...