Search This Blog........

Showing posts with label framework. Show all posts
Showing posts with label framework. 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()


 

Friday, 17 June 2016

Mobile App testing....




                                                               App testing
Android Testing 

Unit Tests 
Separating UI code from code logic is especially hard in Android. For example, an Activity is expected to act as a controller and view at the same time; make sure you keep this in mind when writing unit tests. Another useful recommendation is to decouple unit tests from the Android emulator, this will remove the need to build an APK and install it and your tests will run much faster. Robolectric is a perfect tool for this; it stubs the implementation of the Android platform while running tests. 

Hermetic UI Tests 
A hermetic UI test typically runs as a test without network calls or external dependencies. Once the tests can run in ahermetic environment, a white box testing framework like Espresso can simulate user actions on the UI and is tightly coupled to the app code. Espresso will also synchronize your tests actions with events on the UI thread, reducing flakiness. More information on Espresso is coming in a future Google Testing Blog article. 

Diagram: Non-Hermetic Flow vs. Hermetic Flow


Monkey Tests 
Monkey tests look for crashes and ANRs by stressing your Android application. They exercise pseudo-randomevents like clicks or gestures on the app under test. Monkey test results are reproducible to a certain extent; timing and latency are not completely under your control and can cause a test failure. Re-running the same monkey test against the same configuration will often reproduce these failures, though. If you run them daily against different SDKs, they are very effective at catching bugs earlier in the development cycle of a new release.

iOS Testing 

Unit Tests 
Unit test frameworks like OCUnit, which comes bundled with Xcode, or GTMSenTestcase are both good choices. 

Hermetic UI Tests 
KIF has proven to be a powerful solution for writing Objective-C UI tests. It runs in-process which allows tests to be more tightly coupled with the app under test, making the tests inherently more stable. KIF allows iOS developers to write tests using the same language as their application. 

Following the same paradigm as Android UI tests, you want Objective-C tests to be hermetic. A good approach is to mock the server with pre-canned responses. Since KIF tests run in-process, responses can be built programmatically, making tests easier to maintain and more stable. 

Monkey Tests 
iOS has no equivalent native tool for writing monkey tests as Android does, however this type of test still adds value in iOS (e.g. we found 16 crashes in one of our recent Google+ releases). The Google+ team developed their own custom monkey testing framework, but there are also many third-party options available. 

Backend Testing 

A mobile testing strategy is not complete without testing the integration between server backends and mobile clients. This is especially true when the release cycles of the mobile clients and backends are very different. A replay test strategy can be very effective at preventing backends from breaking mobile clients. The theory behind this strategy is to simulate mobile clients by having a set of golden request and response files that are known to be correct. The replay test suite should then send golden requests to the backend server and assert that the response returned by the server matches the expected golden response. Since client/server responses are often not completely deterministic, you will need to utilize a diffing tool that can ignore expected differences. 

To make this strategy successful you need a way to seed a repeatable data set on the backend and make all dependencies that are not relevant to your backend hermetic. Using in-memory servers with fake data or an RPC replay to external dependencies are good ways of achieving repeatable data sets and hermetic environments. Google+ mobile backend uses Guice for dependency injection, which allows us to easily swap out dependencies with fake implementations during testing and seed data fixtures. 

Diagram: Normal flow vs Replay Tests flow


Conclusion 

Mobile app testing can be very challenging, but building a comprehensive test strategy that understands the nature of different platforms and tools is the key to success. Providing a reliable and hermetic test environment is as important as the tests you write. 

Finally, make sure you prioritize your automation efforts according to your team needs. This is how we prioritize on the Google+ team: 
  1. Unit tests: These should be your first priority in either Android or iOS. They run fast and are less flaky than any other type of tests.
  2. Backend tests: Make sure your backend doesn’t break your mobile clients. Breakages are very likely to happen when the release cycle of mobile clients and backends are different.
  3. UI tests: These are slower by nature and flaky. They also take more time to write and maintain. Make sure you provide coverage for at least the critical paths of your app.
  4. Monkey tests: This is the final step to complete your mobile automation strategy.

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