13 responses to “Notes on Test Automation (I) – Test Encapsulation”

  1. Shrini

    Not clear about the exact meaning of “encapsulation”. Is it same as simply hinding?

    if put all that a test case needs (metadata, configuration, logging settings, execution properties, post processing instructions) in a separate file and have execution logic process this file and run the test — Have I achieved encapsulation?

    Shrini

  2. Rahul Verma

    @Shrini,

    Information hiding is the principle behind encapsulation. Encapsulation is a term widely used in Object oriented programing world, which you can consider as a technique for information hiding. Encapsulation is the way information hiding is achieved for modules/objects. It’s about a combination of external interface in the form of “public” methods and object properties & internal methods which are not exposed publicaly.

    If the data read from the input files mentioned by you is populated outside of the Test object, you haven’t achieved test encapsulation.

    If you place the data in a text/XML/CSV file and (for example) in the constructor of the Test class you populate object variables by reading from this input file, it is in line with test encapsulation.

    Test class would expose a method e.g. run() which would be called from outside the test object. This method would have all the information it needs to execute based on the Test properties already populated.

    The above means the interface for all tests would remain the same and every time the outside logic would call run() method irrespective of which “Test” it is dealing with.

  3. Shrini

    Rahul,

    Thanks… that helps … another naive question related to OO – How doe you distinguish between encapsulation and abstraction.

    If Encapsulation is information hiding (for the purpose of making the life simple for the users of the thing being encapsulated) – what is abstraction?

    Abstraction to me is process of representing idea and relate it to a group of real/concrete objects.

    File system, String Class/Library, TCP/IP framework, certain types of code generators, JVM etc are abstractions to hide the inherrent complexities of the real object that they “attempt” to abstract so that users can work with them easily.

    How do you now compare and contrast the process of abstration and encapsulation in the light of test automation .. some or most of the discussion is in the OO design realm — but we are talking about test automation … hence aski’n you …

    shrini

  4. Rahul Verma

    @Shrini,

    Following is my understanding of these terms (Please validate the same against official OOP resources):

    Representing a real world test case with a TestCase object is an abstraction.

    This object would needs to solve the purpose of the real test case. For the same we would need to think of how the “state of test” can be represented and different actions that it can perform. Some of these actions should be available externally so that other objects can make a TestCase object perform some of these actions.

    Encapsulation is about implementation of this abstraction by providing its structure (object/class variables) and its behavior (external and internal methods) in a language of choice. As per Grady Booch – “encapsulation serves to separate the contractual interface of an abstraction and its implementation.”

    For real world implementation, you would think of an “abstract TestCase class” that has abstract methods like setup(), run(), cleanup(), report(). Any new test case would inherit from this base class and override all these abstract methods to provide concrete implementation of a unique test.

  5. Verand

    Nice Post. I have one question for you though. Do you think, it is possible to use more than one OO language (to tie components together & to describe tests) in TAF?

  6. Rajesh K

    Rahul,
    The article is a very good read. Good to know test automation development approaches is actively looking into object oriented approach. One of the problems we’ve encountered in test automation development is the request from testers to incorporate newer even more complex test scenarios even after the development of automation is complete. The newer test cases even are in most cases incremental changes over an existing test case that’s already automated. One of the ways we’re able to solve this situation is thorough ‘extending’ a test case using object oriented concept. By approaching the test automation problem as object oriented design problem, we were able to model application under test as business classes and associated methods. The first and most noticeable benefit we’re able to achieve is to hide the details of the GUI within business level classes and this has lessened our test case maintenance. I’ve written a blog post about this approach. http://elusivebug.blogspot.com/2009/05/test-automation-approach-object.html
    Regards
    Rajesh

  7. Rahul Verma

    @Verand,

    This is a very important question (and probably a little unusual for many :-) )

    When we want to support multiple OO languages in a single TAF, there has to be a “middle tier” or “translation tier”. Following are some examples:

    - Jython – Can integrate Java/Python code
    - IronPython – Python/DotNet
    - ctypes – Python and C (procedural)
    - Boost Python – Python on top of C/C++
    - SWIG – Python (and several other langs) on top of C/C++
    ….

    The above depend on third party tools/ languages. There can be simpler means of integration via STDOUT/File output, though in such cases you can’t directly talk to the objects/functions from one language to another – it’ output based integration between components. I have used this approach successfully in writing a framework which can possibly run tests in any language.

    Another way (and a little complex one) is employed usually by developers to provide a scripting interface on top of e.g. compiled Code. You can find several such examples of Lua and Python. In such cases the language interpreter is “embedded” in the software written in another language.

    I’ve experimented with some (and not all) of the above ideas with a fair amount of success.

    Hope it helps! I’m planning to write on this subject in the near future as a part of this article series.

    Regards,
    Rahul

  8. Rahul Verma

    @Rajesh,

    Good to hear that you liked the article.

    I agree to your comments. I especially liked the point on business classes. It is very important to keep business classes separate from the generic class hierarchy of the framework so that the core framework can be used by multiple projects.

    Object oriented thinking (though I consider myself at a very preliminary stage as of now) has helped a lot in my test automation framework design efforts.

    Thanks for sharing the link to your post. I’ll read it and share my thoughts.

    Regards,
    Rahul

  9. Verand

    Rahul, excellent high level overview – thanks for sharing.

    >>”I have used this approach successfully in writing a framework which can possibly run tests in any language.”
    I am glad that you already experienced with multi OO language support TAFs.

    I have been developing a few “Hybrid” test automation frameworks using Java & C#. But TAF of multiple OO language support is something that I’m really looking forward to apply in a manner consistent with its purpose.

    I’m interested in your thoughts on some more details on this topic in your next series. All the best!:)

  10. Rajesh

    @Verand,
    It’d be interesting for us to know what’s the context in which you have a requirement for using multiple OO languages? Is it an GUI application or API that you are developing the framework for?

  11. Rajesh K

    @Rahul,
    We’d be very interested in understanding the architecture and design of your framework. Looking forward to the subsequent posts in this series.
    I’d also come across an interesting article by Michael Hunter http://www.thebraidytester.com/downloads/CaptureTheEssenceOfYourTestCases.pdf on Object Oriented approach of test automation.
    Regards
    Rajesh

  12. Rahul Verma

    @ Verand, Rajesh,

    Thanks for visiting again. Please subscribe via the RSS feed so that you are informed regarding the news on further articles of the series.

    FYI, my next article in the series is on high level models of distributed testing.

    I’ve got a related talk scheduled for PyCon India’2010 as well which is scheduled this month at Bangalore, India.

    @Rajesh.
    Thanks for sharing the link.

    Regards,
    Rahul

  13. Verand

    @Rajesh,

    My requirement is “to learn” :-) . Don’t you think there is power in information.

Leave a Reply

Copyright © Testing Perspective,