Showing posts with label packt publishing. Show all posts
Showing posts with label packt publishing. Show all posts

Sunday, December 15, 2013

Win Free Copies of Instant Mock Testing with PowerMock

Here's some good news, I have teamed up with Packt Publishing and we are organizing a Giveaway for you to celebrate the release of my book and two lucky winners stand a chance to win an e-copy of Instant Mock Testing with PowerMock.

What will you get out of this book:

The Cover Page for Mock Testing With PowerMock
  • Understand how to unit test code using PowerMock, through hands-on-examples
  • Learn how to avoid unwanted behavior of code using PowerMock for testing
  • Explore the features of PowerMock through the selection of clear, practical, step-by-step recipes 
Read more about this book and download free Sample Chapter: http://www.packtpub.com/mock-testing-with-powermock/book

How to Enter the contest?

All you need to do is head on over to the http://www.packtpub.com/mock-testing-with-powermock/book and look through the product description of this book and drop a line via the comments below to let us know what interests you the most about this book.
It’s that simple

Dead Line:
 
Like all good things, this offer does not last for ever.  The contest will close on 31/ 12/ 2013. Winners will be contacted by email, so be sure to use your real email address when you comment.

Till we meet again, Merry Christmas and a Very Happy New Year!

Thursday, October 31, 2013

An Author Is Born - Instant Mock Testing with PowerMock

After quite a few long nights and working weekends, finally the book written by me on PowerMock is published and is available to be bought here, here and here.  It’s available in Paperback and almost all major eBook format.

It’s a book for anyone who wants to learn/master mock testing with PowerMock using the Mockito API.  If you are keen on learning a mocking framework that can mock almost any class, PowerMock is the way to go.  Starting with a basic example of how to create a mock and verify a method invocation, Instant Mock Testing with PowerMock demonstrates various features of PowerMock using clear, practical, step-by-step recipes. 

Moving on from the basics, you will learn how to write unit tests for static, final, and private methods, and write flexible unit tests using argument matchers. Following on from this, you will also learn how to invoke real implementation of some methods and mock only a few methods of a class, using partial mocks or spies. This book will teach you all tricks of the trade and enable you to write good unit tests for a wide range of scenarios.

The Back and Front Cover of the Book
Any feedback would be greatly appreciated (if you want to buy it, please let me know, I can get some deep – pun intended :) – discounts using the Author discount code).

I would like to thank Jayway and the Java Community for a great mocking framework.
I cannot imagine finishing this book without the dedication and support of my loving family, who put up with long nights and working weekends for far longer than I had initially planned for.  

Lastly, I would also want to thank PACKT Publishing and their entire team, without whose efforts this book would have been impossible.  It would be inappropriate on my part, if I didn't extend my special thanks to Govindan, Sherin and Aparna from PACKT Publishing.
I would conclude this post with the preface of the book for your reference:

 Preface
PowerMock is an open source mocking library for the Java world. It extends the existing mocking frameworks such as EasyMocks (see http://www.easymock.org/) and Mockito (see http://code.google.com/p/mockito/) to add even more powerful features to them.
PowerMock was founded by Jayway (see http://www.jayway.com/) and is hosted on Google Code (see http://code.google.com/p/powermock/).
It has a vibrant community with a lot of contributors. Conscious efforts have been made to ensure that PowerMock does not reinvent the wheel. It only extends existing mocking frameworks and adds features that are missing from them. The end result is a mocking library that is powerful and is a pleasure to use.
Sometimes a good design might have to be tweaked to enable testability. For example, use of final classes or methods should be avoided, private methods might need to open up a bit by making them package visible or protected, and use of static methods should be avoided at all costs. Sometimes these decisions might be valid, but if they are taken only because of limitations in existing mocking frameworks, they are incorrect. PowerMock tries to solve this problem. It enables us to write unit tests for almost any situation.
What this book covers
Saying Hello World! (Simple) explains a basic mocking example using PowerMock. It will help us get familiarized with basic mocking and verification syntax.
Getting and installing PowerMock (Simple) demonstrates the steps for setting up PowerMock using IntelliJ IDEA and Eclipse. It also briefly describes other ways of setting up the PowerMock environment.
Mocking static methods (Simple) shows how effortlessly we can mock static methods with PowerMock. Most of the mocking frameworks have trouble mocking static methods. But for Power Mock, it’s just another day at work.
Verifying method invocation (Simple) explains various ways in which we can verify a certain method invocation. Verification is an indispensable part of unit testing.  
Mocking final classes or methods (Simple) covers how easily we can mock final classes or methods. Mocking final classes or methods is something that most mocking frameworks struggle with. Because of this restriction, sometimes a good design is sacrificed.
Mocking constructors (Medium) introduces the art of mocking constructors. Is a class doing too much in its constructor? With PowerMock, we can mock the constructor and peacefully write tests for our own code.
Understanding argument matchers (Medium) demonstrates how to write flexible unit tests using argument matchers. Only verifying that a certain method was invoked is a job half done. Asserting that it was invoked with correct parameters is equally important.
Understanding the Answer interface (Advanced) demonstrates the use of the Answer interface, using which we can create some unusual mocking strategies. Sometimes mocking requirements are extremely complex, which makes it impractical to create mocks in the traditional way. The Answer interface can be used for such cases.
Partial mocking with spies (Advanced) explains the steps to mock only a few methods of a given class while invoking the real implementation for all other methods. This is achieved in PowerMock by creating spies.
Mocking private methods (Medium) covers the steps to mock and verify private methods. Private methods are difficult to test with traditional mocking frameworks. But for PowerMock, it’s a piece of cake.
Breaking the encapsulation (Advanced) shows how we can test the behavior of a private method and verifies the internal state of a class using the Whitebox class. At times, some private method might be performing an important business operation and we need to write unit tests for that method. The Whitebox class can be very handy in such situations.
Suppressing unwanted behavior (Advanced) explains how we can suppress unwanted behavior such as static initializers, constructors, methods, and fields.
Understanding Mock Policies (Advanced) demonstrates the use of Mock Policies to better manage the repeated code needed to set up mocks for a complex object.
Listening with listeners (Medium) demonstrates the steps to listen for events from the test framework. We might want to do some processing when the test method is invoked or create a report about how many tests were run, how many passed, how many failed, and so on. Listeners are a good fit for such requirements.

Saturday, February 26, 2011

Review of - The Selenium Testing Tools - Beginner's Guide

As mentioned in one of previous post, I got an opportunity to review a book on Selenium call - The Selenium Testing Tools - Beginner's Guide from PACKT Publishing.

Selenium 1.0 Testing Tools: Beginner’s Guide

I had used Selenium in lot of my projects, I thought, I knew selenium quiet well before reading the book.  After reading the book, I realized that, I had only partial knowledge about Selenium.  I knew how to do things, but the book taught me, how to do them in many different ways and what was the best way in a given situation.

The book, taught me lot of new things about Selenium.  For example, I always thought that, using Selenium IDE, one cannot write maintainable tests, but after reading the book, I realized that if one follow the patterns mentioned in the book, one can easily write maintainable tests simply using Selenium IDE.

Moreover, non-programmers can convert the Selenium IDE tests to programming API tests in a matter of few clicks!

There are may good things that, I could take away from the book, here are a few that stood out:

  • Starts of from the very basics.  The book start with installation of Selenium IDE, Firebug and Firefinder add-ons to Firefox.  Because of this, someone who has never worked with selenium before, can quick start and write their first selenium tests in a matter for minutes
  • While reading some books, I get lost and have to figure out how to do a certain step.  But things are different with this book, there are screenshots for almost every thing.  For every step that book shows there is a Screenshots.  This helps us understand the concepts in a much better way.
  • Book encourages the use of best practices.  For example, book clearly explains why the test cases should be independent of each other and how one could achieve that.  Book encourages the use of Firebug and Firefinder.  These are two tools which every web-develop/web-QA should know for sure!
  • Explains how one can convert Selenium IDE test to programming tests using just the Selenium IDE.  I did try it and it does work!
  • Book Explains how we could use Selenium Grid to parallelize our tests.  Using Selenium Grid we could target our tests to run on a certain browser on a certain OS.  For example, we could configure that Test1 should run on "Firefox on Mac" or "IE on Windows".  Using this feature you can test your application on lot of platforms and browsers without a lot of pain!
  • Demonstrates advanced techniques like Cookie handling using Selenium API
  • A full chapter dedicated to Selenium 2
  • At various steps, the book presents the user with Popup Quizzes, these are helpful to test what we have learned!
  • Explains the Page Pattern.  While writing the Selenium tests using the Programming API, its extremely important that we do not repeat code for every test.  Book explains how we could achieve maximum reuse of code.  End result, more maintainable and easy to write/read tests!
  • Explains various techniques like xpath, regexp, css and javascript to locate an element.  Its extremely necessary that we learn how to locate the element efficiently.  Using the right technique at the right place could result in faster and easy to read tests.  For example using xpath at a place where css could have been used would result in slower tests!
  • Explains the use of user extensions.
Those are some of the take away's for me from the Book.  

The book has much more to offer than, what I have described here.  Take my advice, do not waste any time and grab a copy of the book from here!

Monday, February 7, 2011

Learning good things about Selenium - The Functional Testing Tool

Recently, I have been learning a lot of good things about Selenium. All thanks to this book, Selenium 1.0 Testing Tools - Beginner's Guide.

Selenium 1.0 Testing Tools: Beginner’s Guide

I got an opportunity to review this book from PACKT Publishing. I have just started reading the book, but I can tell you one thing, it gives great start at working with Selenium.

What is Selenium?

Selenium is an opensource automated testing tool for testing web application.  Using Selenium we can write test cases to test the web application in a black box environment.

Quoting from the book:

Test automation has grown in popularity over the years because teams do not have the time or money to invest in large test teams to make sure that applications work as they are expected to. Developers want to make sure that the code they have created works as they expect it to.


As time has passed developers and QA's have realized that automated functional tests provide a great safety net for catching bugs early in development life-cycle.  Selenium makes writing/executing functional tests extremely easily.

We can record and playback the tests directly in firefox using the Slenium IDE!  Selenium also provides programming api to write functional tests in Java, C#, Ruby , PHP, Perl and Python.

Once the tests are written (using the programming API or Selenium IDE) they can be execute as often as one wants using the Selenium RC (remote control) or Selenium Grid!  Over and above it the test can be executed in variety of browsers including IE, Firefox, Opera and Safari!

Selenium can be used to simulate any work flow.  I have been in situations where, because the team had written Selenium tests, a bug was caught early in the development life-cycle, which would otherwise be caught very late.  End result lot of time and money was saved because of Selenium!

The things I am blabbering (about Selenium) in this post are covered in much greater detail in the book.  Simply by reading the first few pages I was able to write a functional test using Selenium IDE.

Some of the good things I have noticed about the book so far:
  • Starts from basics.  The book starts of by guiding users through the installation process of Selenium IDE.  Goes on to explain how to write a simple functional test (using Selenium IDE), with an example.
  • Easy to read.  Its very important that books are written in simple language so that everyone can read it easily.  People with/without programming background can read this book with equal ease and extract useful information out of it.
  • All concepts are explained using examples and lots of screen shots.
These are just initial impressions about the book.  I am sure, I will discover many more good things about the book, as I continue reading further!

Stay tuned folks!  Full review of the book coming up very soon!
Have some Fun!