Wednesday, February 24, 2016

JASMINE - A Unit Testing Framework

Any small or medium or large App does require unit tests to verify quality of the code during development stage itself. And this provides flexibility to easily change or modify code without worrying about breaking any regressions.

Before even getting into let’s understand BDD S/W development process.  BDD as it stands for behavior-driven development emerged from Test-driven development. BDD comprises of techniques and principles of TDD to provide ease on collaboration.

Jasmine, a JS unit test BDD framework, for validating JS functions. Jasmine does not have any dependency on DOM elements nor depends on any other JS unit test framework. This comes with it’s own syntax to write efficient tests.

Here’s you can get code for Jasnmine:

Jasmine provides flexibility either to use Ruby or Python. Once the setup is done as per above given instructions, you can start developing unit tests. It is advisable to develop your unit tests first and then write code.

Angular framework has written by keeping testability in mind. Jasmine whole-heartedly support any app built using Angular just like Mocha or qunit etc

You want to write a unit test for a simple mathematics equation

Sample code:
Describe (‘Maths, function () {

//necessary
it(‘should add two numbers accurately’, function() {});
it(‘should subtracts two numbers accurately’, function() {});

});

describe() method describes test suite. It() describes spec.

For Angular’s simple controller you can write below unit test:
var myApp = angular.module('myApp',[]);  myApp.controller('GreetingController', ['$scope', function($scope) {   $scope.greeting = 'Hola!'; }]);

describe(‘GreetingsController Example’, function() {
var GreetingController,
scope;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
.
.
.
.});

Now you have an example of basic unit test using Jasmine. You can run all your tests on every commit. These tests are very lightweight, and executes faster.
Achieving Continuous deployment makes it easy.

On Jenkins, you can install a command line with grunt plugin. Add the command line argument in your Jenkins config file.

You can see a sample output here:


Tuesday, August 31, 2010

All About World of Mobile!

Mobile in general is such niche area and glad that at LinkedIn, I am getting to explore as well as expand new horizon.

My team is focus on supporting Mobile native apps, hybrid app as well as mobile web software test cycles.

I may not be able to write more here but look forward to a blog from me on engineering.linkedin.com

Tuesday, July 6, 2010

Exploratory Testing - Innovative approach

Exploratory testing is an approach to software testing that is concisely described as simultaneous learning, test design and test execution. While the software is being tested, the tester learns things that together with experience and creativity generates new good tests to run. Exploratory testing is often thought of as a black box testing technique. Instead, those who have studied it consider it a test approach that can be applied to any test technique, at any stage in the development process. The key is not the test technique nor the item being tested or reviewed; the key is the cognitive engagement of the tester, and the tester's responsibility for managing his or her time. (Ref: Wikipedia)


In a resource crunch situation, especially, when the new features are coming in to huge extent, this innovative approach can make wonders! However appropriate planning, organizing and motivation is desirable to make this approach a success.


In short, the approach, involves, getting various stake holders like engineering team members, product managers, UX team members, customer field representatives together and perform an exploratory testing... on given feature or product. It could be simple web 2.0 product or it could be wireless device...does not matter.


As long as QA manager/lead outlines proper strategy....and a step by step representation of how to effectively perform exploratory testing or corner case testing... Once you have such step by step guide you can always give a preso to above stakeholders and get them up to speed with concept of exploratory testing. And you can pin point exact ways to make it effective and get best out of it!!


When I had conducted this approach, I had come up with 10 steps of effective ways.... think like an end user, act like an end user....relevant to the product that I wanted to get tested thoroughly,... Made sure to get buy in from VP/ Director initially by explaining them approach, impact and result! Rolled it out to engineering. Then got buy in from product manager(s). Rolled it out to them and then field representatives as they deal with customers and they know the issues or most common operations by customers.


Overall to avoid duplication of bugs, we have had everyone perform testing at the same time..no matter where they are located within USA :) And then set up IRC channel where constant communication of issues seen was going on to avoid duplication of bugs.


Result..we actually end up finding some of the corner case issues, high priority issues! We ended up adding almost 35+ test scenarios in our test repository and automating the same!!


This was very well received by my engineering team as well as product manager. Helped save a lot of QA time of performing black box - exploratory testing ..



Monday, June 21, 2010

Selenium wait()

Selenium wait() not defined ? What will happen ?

Selenium uses the browser to make requests and process the server response. In short, selenium asks for a page and server sends back the response.
The browser then constructs a DOM tree out of the response. Selenium then parses this DOM tree and looks for elements as per the test statements.

Short example
Step 1 --> @selenium.open("www.google.com")
Step 2 --> @selenium.wait()
Step 3--> @selenium.is_text_present("Google ...")

Here the request is Step 1.

Now assuming that the server is not loaded at all, the network latency is very minimal and the client machine has a very fast processor, the time from the first request to receiving the response will STILL be atleast a few miliseconds. So not considering the network latency and delayed response from the server, some time is definitely required for the browser to generate a DOM tree out of the response and then ready the page to be rendered.

If we do not allow for a wait period, however small it maybe due to ideal network and server load conditions, then selenium will jump from step 1 to step 3. At this point, the DOM tree is not ready and selenium will NOT find the text "Google ..." in the DOM tree. Thus, our test will fail.

For any test environments, the server response times could be large and selenium has to wait for the response to be completely consumed by the browser and build a DOM tree. Even if we were to make the test environments extremely fast and run at almost no load, there will be some amount of time required for DOM tree creation and parsing :)

Hence wait() is a basic required function for Selenium and can not be avoided :(

Saturday, June 19, 2010

How to be innovative and how to keep yourself motivated

At work some times it could be possible that you end up working on certain project and may end up performing kinda similar tasks w/very little variations... So would that become monotonous ?

Do you think if it becomes monotonous..you may loose productivity to some extent and to help performing excellent at work, you need your motivation to be boost ?

Well, here is how I keep myself motivated - whether its work or cooking in kitchen. Coming from an Indian background, I almost end up preparing similar kinda breakfast with little variations...my family may get bored with same taste over and over again so I try to add different spices or motivate myself to try creative recipes for the same dish :) Well that truly helps!

I found below an interesting article published which helps self-motivation:
http://business.timesonline.co.uk/tol/business/management/article5883575.ece

Friday, June 18, 2010

JMeter or Selenium - Performance Testing of Web App

Some one recently asked me an interesting question "which tool better for performance testing for given web app - Selenium ? or any other open source ?"

Well here is my take

Tuesday, June 8, 2010

Find bugs - Static Analysis To Look For Bugs In Java code

Find Bugs - A static analysis tool to find logical error in given code snippet. Basically it helps find bugs in Java code. This comes as an Eclipse plug-in.

There is a way you can integrate Find bugs into the source control you are using for example Perforce.

This should be integrated on each and every development environment of developer's whether Eclipse or IntelliJ. As you go on writing code, this tool will immediately display errors which could cause eventually potential bugs with coding right away. So it saves time of developers handing over code to QA, QA performs testing and reporting back these bugs. Here is published material bu Find Bugs community as it was used @Google for product AdWords:

Published Material:Find Bugs Approach As Published