CherryPy Testing - cherryPy

What is Testing?

Testing is a process in which the application is tested from different angles in order to −

  • Find the list of issues
  • Find differences between the expected result and actual result, output, states, etc.
  • Understand the implementation phase.
  • Find the application useful for realistic purposes.

The objective of testing is not to point the developer’s mistake but to facilitate tools and aiming at improving the quality to judge the health of the application at a given time.

Testing should be planned in prior. This calls for defining the objective of testing, knowing the scope of test cases, making the list of business needs and being familiar of the liabilities includes in the various stages of the project.

Testing is described as a range of features to be validated on a application or system. Below are the list of the test approaches which re commonly used −

Unit testing − This is generally performed by the developers themselves. The main purpose of unit testing is to check whether a unit of code works as expected or not.

Usability testing − Developers may generally does not keep in mind that they are developing an application for the end users who usually do not have awareness of the system. Usability testing tests for the advantages and disadvantages of the product/application.

Functional/Acceptance testing −Usability testing merely tests whether a system or application is usable or not where as functional testing validates that every specified functionality is implemented.

Load and performance testing − This is performed to understand whether the system can handle the specified load or not and performance tests to be conducted. This will result in changes in optimizing SQL queries, hardware etc.

Regression testing − It is done to make sure that the successive releases have not resulted in breaking of previous functionalities.

Reliability and resilience testing − Reliability testing is performed to validate the system with the breakdown of one or more components.

What is Unit Testing?

Photoblog applications always use unit testing to test the following −

  • New functionalities work rightly and as expected.
  • To make sure that the existing functionalities are not broken by new code release.
  • Defects are fixed and remain fixed.
  • Python comes up with a standard unit test module giving a different approach to unit testing.


unittest is rooted in JUnit, a Java unit test package which was developed by Kent Beck and Erich Gamma. Unit tests simply return defined data. Mock objects can be defined. These objects permits testing against an interface of our design without need to depend on the whole application. They also facilitate a way to run tests in isolation mode including with other tests.

Let us define a dummy class in the below way −

The illustration for the code is as follows −

  • unittest module must be imported in order to provide unit test capabilities for the specified class.
  • A class must be created by subclassing unittest.
  • Each method in the mentioned code begins with a word test. All these methods are called by unittest handler.
  • The methods assert/fail are called by the test case to manage the exceptions.

Take this as an example for running a test case −

The result for executing the test case will be as shown below −

What is Functional Testing?

Once the application/sysytem functionalities begin taking shape according to the requirements, a set of functional testing can verify the application's rightness as per the specification. However, the test need to be automated for good performance which will require the use of third-party services such as Selenium.

CherryPy facilitates helper class like pre-defined functions to make simple the writing of functional tests.

What is Load Testing?

In order to detect performance bottlenecks in the application that are not permitting it from attaining a certain level of performance, one have to perform load and performance testing.

This section will not describe in detail how to perform a performance or load test as it is out of its the FunkLoad package.

The very fundamental example of FunkLoad is as shown below −

Here is a detailed illustration of the above code −

The test case should be taken from the FunkLoad TestCase class so that the FunkLoad can perform its internal job of recording what is happening during the test.

The name of class is very important as FunkLoad will see for a file based on the class name.

The test cases which are designed will have direct access to the configuration files. Post() and Get() methods are simply called across the server to get the output.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

cherryPy Topics