Testing is a typical phase in the Web application development flow, because a Web application is made of multiple layers of logic starting from HTTP request handling, to request data validation and processing, to template rendering.
But testing phase of a Django Application development, it’s really easy. We use Unittest module built in to python standard library to write the test cases to simulate requests, insert the test data and inspect the application’s output.
You can perform automated testing in your Django application using different tools. Few of them are,
In this blog, let's try to learn of what is Robot framework and how to write simple test cases using robot framework.
Robot Framework is one of the best testing automation frameworks for acceptance testing. Which can be very useful in the acceptance test-driven development. This framework uses a keyword-driven testing approach, and it has easy-to-use tabular test data syntax, which is a very effective way to achieve user acceptance testing. This framework is having an extensive amount of test libraries implemented either with Python or Java. The testers can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases. Robot framework is implemented using Python, and it can run also on Jython (JVM) and IronPython (.NET).
You can install robot framework with the following command
pip install robotframework
Starting from Robot Framework 3.0, tests are executed using the robot script and results post-processed with the robot script: The following is the syntax to run the test cases
robot tests.robot robot output.xml
The other way to run tests is executing the installed robot module is directly using Python's -m command line option.
python -m robot tests.robot python -m robot.rebot output.xml
As we discussed in the beginning of this blog post Robot framework uses a keyword-driven testing approach, and It has easy-to-use tabular test data syntax. Lets us start with a simple example of user account creation and sign in process. Following are the two cases that we try in this example.
*** Test Cases *** User can create an account and log in Create Valid User fred P4ssw0rd Attempt to Login with Credentials fred P4ssw0rd Status Should Be Logged In User cannot log in with bad password Create Valid User betty P4ssw0rd Attempt to Login with Credentials betty wrong Status Should Be Access Denied
In the above example, the syntax is more like natural English language rather than complex programming language style syntaxes.
You can save this with .robot extension and execute the test case using
robot myfirsttest.robot robot output.xml
As discussed in this blog post, keywords are the major essentials of this framework. The keywords can be created keywords that can come from two sources.
We can discuss more about keywords, variables in coming blog posts on Robot framework.
Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.
Django-CRM :Customer relationship management based on Django
Django-blog-it : django blog with complete customization and ready to use with one click installer Edit
Django-webpacker : A django compressor tool
Django-MFA : Multi Factor Authentication
Docker-box : Web Interface to manage full blown docker containers and imagesMore...