Search This Blog........

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, 13 July 2016

Python unit testing

Python Unit testing tutorial



Unit test: 
Using python default unittest allows you to write more robust tests.

The unittest module  provides a runner to execute tests i.e, grouping tests in to logical unit and the concept of setup and teardown.
Lets see one example.....,
import unittest

class Test(unittest.TestCase):
    def setUp(self):
        self.num=1

    def test_math(self):
        self.assertEqual(self.num,1)


if __name__ ==  '__main__':
    unittest,main()   


Explanation
A testcase is class that inherits from unittest.
The function(def) inside class all require a mandatory parameter named self 
When running unittest.main(), that take care of finding all the testcases. Calling setUp method first (whose name start with test) and then finally calling method called tearDown()


 

Sunday, 29 May 2016

Robot framework

Robot framework (Python)

Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD).
Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases. 

Installation of Robot framework:

The following steps to install robot framework in Windows OS.
1) Download & Install python 2.7.x version from the below link and install it with "Run as Administrator" 

 ----> Open the command prompt and check python version. Shown Below.
CMD: python --version
 Note: Add the path to Window environmental variable

2) Install Robot framework using PIP command
CMD: pip install robotframwork 
Check installation using the command shown in below pic.
3) Now install selenium2library and selenium library

CMD: pip install robotframework-selenium2library