Ukraine Office: +38 (063) 50 74 707

USA Office: +1 (212) 203-8264

contact@testmatick.com

Manual Testing

Ensure the highest quality for your software with our manual testing services.

Mobile Testing

Optimize your mobile apps for flawless performance across all devices and platforms with our comprehensive mobile testing services.

Automated Testing

Enhance your software development with our automated testing services, designed to boost efficiency.

Functional Testing

Refine your application’s core functionality with our functional testing services

VIEW ALL SERVICES 

Discussion – 

0

Discussion – 

0

Encapsulation as One of the Fundamental Principles of Object-Oriented Programming

Encapsulation-as-One-of-the-Fundamental-Principles-of-Object-Oriented-Programming

Knowing the basics of object-oriented programming is necessary not only for programmers, but also, of course, for testers who interact with program code, study it, or write it. Insight into programming fundamentals enables QA experts to better understand the program behavior, give effective recommendations on how to improve the structure of program code, and, more efficiently create autotest code.

Concept of Encapsulation

Encapsulation is a set of practices for hiding parts of the implementation, or the internal state of an object and selectively allowing access to internal mechanics through certain public methods. It is often used to directly prevent users from accessing an object and editing these properties, for web security purposes or to prevent deliberate changes to information.

An Example of Using Encapsulation in Program Code

To visually examine the use of encapsulation and its properties, let’s say that we have some TEST class which is a bank account with 2 features: type of account and account balance.

So, the simplest display of such a class can look like this:

TEST class

TEST class

It is very formulaic and raises a lot of questions. The most relevant one is that all the users of this class can update the values of the bank balance properties as they want when they perform bank withdrawals or deposit actions.

And this is not a good idea. No one can guarantee that the business rules are followed correctly because such operations cannot impose “correct system behavior”.

It is much better to use the basics of encapsulation. To do this we can make the properties hidden by restricting direct access to them with the TEST class. Then we give access to the property through public methods, adding some business rules along the way:

public class TEST

public class TEST

When encapsulation is used and some kind of business rules are imposed, it becomes unrealistic to withdraw a negative amount of money or to put a minus value of funds into a user account. The real balance is still available to everyone, but access is now limited to read parameters.

The Role of Encapsulation in Automation

The most common use of the basics of encapsulation in the field of test automation is Page Object, which, in turn, is widely used because of its user-friendly interface based on tools such as Selenium, Playwright, and Cypress.

As we know, Page Object are special classes that encapsulate the details of page creation, locators used to verify elements on a web page, and used in test checks.

An Example of Page Object Encapsulation

Let’s take a small example of a LoginPage object that hides implementation basics in private parameters, and gives access to them through simple test manipulations that are defined in public methods.

public class LoginPage

public class LoginPage

The “user” of such a class can operate on elements that are defined in the class exclusively through a public method without direct access to the details of page implementation – e.g., the HTML structure. All this leads to a clean API for the page object class and efficient separation of interests.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like

Test Automation Strategies That Really Work

Test Automation Strategies That Really Work

An approach to the development and implementation of automated tests for an application-in-test depends on numerous factors. A size and complexity of an application, a structure of a project team, instantly appearing deadlines, requirements for security, and many other details define the most suitable strategy. Further, we will describe some working strategies that can be helpful for any project that requires automation.

Using Test Retries as a Method to Hide Bugs

Using Test Retries as a Method to Hide Bugs

Every tester is in some way familiar with the concept of randomly failing automated tests. An analysis of the results of these tests can be really time-consuming and some teams prefer running tests once again if they fail. But is this efficient? The answer is not as obvious and clear as it seems.