For more information on automation, please click here ->>>>

Four core elements Test Case: A Test Case is the smallest unit of Test execution in UnitTest. Unittest provides a base class called TestCase that you can use to create test cases, and a case is a use case. Test Suite: A Test Suite is a collection of tests or Test cases. It is a set of tests created for the corresponding functions and modules of the program under Test. The Test cases within a Test Suite are executed together. Test Runner: The Test executor is responsible for scheduling Test execution and generating Test results for users. The test executor can display test execution results using a graphical interface, a text interface, or a specific return value. Test fixtures: You use Test fixtures to define preparation before and cleanup after a single or multiple Test executions. TestFixture tests the use of fixture setUp and tearDown: def setUp(self) -> start destruct: def tearDown(self) -> end fixture

Both methods inherit from the TestCase class setUp method to do what happens before each use case starts, such as opening a browser or logging in. The tearDown method performs operations after each use case, such as closing the browser, logging out, and clearing log handles. Both methods are executed each time before each test case.

 

Def setUpClass(self) -> start

Def tearDownClass(self) -> end

Description:

The setUpClass and tearDownClass methods are only executed once in a test class. To use these methods, you must add a classMethod decorator

 

TestCase Use: Import unitTest package -> Create Test class inherit unitTest. TestCase class

Description:

Each use case in an automated test is a completed process. The test method name must start with test, because TestCase cannot retrieve test cases unless it searches for methods that start with test when it runs test cases in batches

 

TestSuite addTest(ClassName(MethodName)) instantiates the Suite class, Suite = unittest.testSuite () adds a case, Suite. AddTest (ClassName(MethodName))

You can add only one use case at a time. You need to add multiple use cases

 

AddTests uses: suite.addTest([ClassName(MethodName),ClassName(MethodName)])

This method can add more than one use case at a time, and the passed arguments must be lists

 

The discover method iterates through the specified directory by conditional filtering and returns the test suite -case_dir: -pattern: this is the name of the script to be executed. Test *. Py means to match all scripts starting with test. -top_level_DIR: This is the name of the top-level directory

  • The set of test cases generated by the above method need to be executed in conjunction with TextTestRunner

TestRunner test executor uses:

Instantiate runner= unitTest.texttestrunner () execute run to pass test suites, Runner. Run (suites)

The skip method skips tests using:

This method is a decorator in the UnitTest framework, using the method @unittest.skip(parameter)

Description:

-skip method skips execution. -skipunless method condition is False. -skipif method condition is True

 

Assertions in the UnitTest framework use:

TestCase class inherits from TestCase class

 

Description:

In the case of equal, two pairs of ratios are passed and MSG throws an error message