Rest Assured Testing Framework

Testing and validating REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of using these languages into the Java domain.

Our testing framework integrates the Rest Assured library with Java project along with other essentials like TestNG framework, logging, reporting, etc. You can kick-off any rest-assured java project using this framework easily.

Technology and plugins used

This framework uses the following technology stack :

Project Structure

image1

Our testing framework project consists of the following classes :

  • Test.java.ApiTest.java – This is the java class where all the test cases are written that need to be executed. Currently, we have only one java file here, but based upon your requirements you can create multiple java files here to create a test suite. Please note, you should avoid hard coding any test data in these java classes, for example – API endpoints, parameter queries, etc. This java class should only contain the call to relevant test methods and the assertions.
  • Test.resources.ApiData.java – With this java class, we define all the test data that we need like API endpoints, query parameters, methods to call each API endpoint, etc. Please note, there should be no assertions in this java class. It is meant only for defining the test data and methods.
  • Test.resources.ApiMethods.java – This java class primarily consists of two methods. One is a generic method for sending a GET request and the other is a generic method for sending a POST request. Each method returns the Response object as an argument. You can add more generic methods here if you want to include more types of requests like PUT etc.

How to write test cases

Each test case in this framework should contain a call to a method that should be defined in ApiData.java class and it should return the Response (Json) as the output. The test case should parse the Response object and apply assertions where ever required.

Let’s the first test from the framework as an example.

@Test (priority=1, description="Testing post request by fetching the GSE queue data.") public void TestPostRequest(){ log.debug("Sending the post request to the API"); Response response = api.postFetchQueue(); log.debug("Evaluating assertions on the fecthed response after sending post request to API"); Assert.assertEquals(response.getStatusCode(), 200); }

Let’s start with the explanation of each line in the test case code –

  1. @Test (priority=1, description=“Testing post request by fetching the GSE queue
    This is the general annotation for TestNG.@Test denotes that this is the test case method and should be executed as a test case.
    priority=1 is the test case priority during execution. Higher priority test cases are executed first.
    the description is the test case description which will appear in a report next to the test case name.You can refer to the following link for some basic TestNG annotations:
    https://www.tutorialspoint.com/testng/testng_basic_annotations.htm
  2. log.debug(“Sending the post request to the API”);
    This is the method for Log4J module to add a debug log.
    To know more about logging methods of Log4J, please refer:
    https://www.tutorialspoint.com/log4j/log4j_logging_methods.htm
  3. Response response = api.postFetchQueue();
    Here we are making a call to the methods postFetchQueue() which is defined in ApiData.java class. ‘api’ is an object of ApiData.java class. This method makes a POST request to the fetch queue endpoint of our API. And the response returned by this method is collected to the Response type object which is a class defined in Rest Assured libraries.
  4. Assert.assertEquals(response.getStatusCode(), 200);
    This is an assertion where we are checking the API request’s response status code which should be 200 for a successful call to the API endpoint.

How to write API request method in ApiMethods.java

Let’s the postRequest() method as an example from ApiMethods.java

public Response postRequest(String endpoint, JSONObject jsonData) { RequestSpecification request = RestAssured.given(); request.header("Content-Type", "application/json"); request.body(jsonData.toJSONString()); Response response = request.post(endpoint); return response; }

  1. public Response postRequest(String endpoint, JSONObject jsonData)
    This method takes two arguments, one is of String type and contains the API endpoint, other is of JSONObject type and contains the JSON data which is required to be attached with the POST request.
  2. RequestSpecification request = RestAssured.given();
    This is a generic statement for the Rest Assured library for specifying the specifications. This should not be changed.
  3. request.header(“Content-Type”, “application/json”);
    This statement adds the header for the POST request which should be “application/JSON” as the content type for our example because we are attaching the JSON data with the POST request.
  4. request.body(jsonData.toJSONString());
    Here we are attaching the Json data compiled in the previous step to the request body as a JSON converted to string.
  5. Response response = request.post(endpoint);
    With this statement we are finally making a POST request call to the desired endpoint. Note that we have already attached the headers and the Json data to the request object in step-3 and 4.
    The response is collected in the Response type object and returned back.

How to run the test suite

First, we need to install Maven on our system. Please follow the below-mentioned guide to install Maven on Windows system:

https://www.mkyong.com/maven/how-to-install-maven-in-windows/

Once installed successfully, open command prompt as an administrator and navigate to the root directory of your project and execute the following command :

mvn clean test

It should first resolve all the dependencies and download all required JARs. Then the test execution should start.
 

How to view the Allure report of test execution

To view the Allure report, we first need to install Allure command-line tool on our system using the following guide:

https://docs.qameta.io/allure/#_installing_a_commandline

Once installed, please execute the following command in command prompt as an administrator :

allure serve allure-results

This command should open the allure report in a new browser.

Know us more at https://www.fleekitsolutions.com/


 

What is GEEK

Buddha Community

Joseph  Murray

Joseph Murray

1621492530

7 Test Frameworks To Follow in 2021 for Java/Fullstack Developers

It is time to learn new test frameworks in 2021 to improve your code quality and decrease the time of your testing phase. Let’s explore 6 options for devs.

It is time to learn new test frameworks to improve your code quality and decrease the time of your testing phase. I have selected six testing frameworks that sound promising. Some have existed for quite a long time but I have not heard about them before.

At the end of the article, please tell me what you think about them and what your favorite ones are.

Robot Framework

Robot Framework is a generic open-source automation framework. It can be used for test automation and robotic process automation (RPA).

Robot Framework is open and extensible and can be integrated with virtually any other tool to create powerful and flexible automation solutions. Being open-source also means that Robot Framework is free to use without licensing costs.

The RoboFramework is a framework** to write test cases and automation processes.** It means that it may replace** your classic combo Selenium + Cucumber + Gherkins**. To be more precise, the Cucumber Gherkins custom implementation you wrote will be handled by RoboFramework and Selenium invoked below.

For the Java developers, this framework can be executed with Maven or Gradle (but less mature for the latter solution).

#java #testing #test #java framework #java frameworks #testing and developing #java testing #robot framework #test framework #2021

Lindsey  Koepp

Lindsey Koepp

1598948520

Top 10 Test Automation Frameworks in 2020

We are moving toward a future where everything is going to be autonomous, fast, and highly efficient. To match the pace of this fast-moving ecosystem, application delivery times will have to be accelerated, but not at the cost of quality. Achieving quality at speed is imperative and therefore quality assurance gets a lot of attention. To fulfill the demands for exceptional quality and faster time to market, automation testing will assume priority. It is becoming necessary for micro, small, and medium-sized enterprises (SMEs) to automate their testing processes. But the most crucial aspect is to choose the right test automation framework. So let’s understand what a test automation framework is.

What Is a Test Automation Framework?

A test automation framework is the scaffolding that is laid to provide an execution environment for the automation test scripts. The framework provides the user with various benefits that help them to develop, execute, and report the automation test scripts efficiently. It is more like a system that was created specifically to automate our tests. In a very simple language, we can say that a framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections, etc. to pillar automation testing. Thus, the user can follow these guidelines while automating applications to take advantage of various productive results.

The advantages can be in different forms like the ease of scripting, scalability, modularity, understandability, process definition, re-usability, cost, maintenance, etc. Thus, to be able to grab these benefits, developers are advised to use one or more of the Test Automation Framework. Moreover, the need for a single and standard Test Automation Framework arises when you have a bunch of developers working on the different modules of the same application and when we want to avoid situations where each of the developers implements his/her approach towards automation. So let’s have a look at different types of test automation frameworks.

Types of Automated Testing Frameworks

Now that we have a basic idea about Automation Frameworks, let’s check out the various types of Test Automation Frameworks available in the marketplace. There is a divergent range of Automation Frameworks available nowadays. These frameworks may differ from each other based on their support to different key factors to do automation like reusability, ease of maintenance, etc.

Types of Test Automation Frameworks:

  1. Module Based Testing Framework
  2. Library Architecture Testing Framework
  3. Data-Driven Testing Framework
  4. Keyword Driven Testing Framework
  5. Hybrid Testing Framework
  6. Behavior Driven Development Framework

Benefits of a Test Automation Framework

Apart from the minimal manual intervention required in automation testing, there are many advantages of using a test automation framework. Some of them are listed below:

  1. Faster time-to-market: Using a good test automation framework helps reduce the time-to-market of an application by allowing constant execution of test cases. Once automated, the test library execution is faster and runs longer than manual testing.
  2. Earlier detection of defects: The documentation of software defects becomes considerably easier for the testing teams. It increases the overall development speed while ensuring correct functionality across areas. The earlier a defect is identified, the more cost-effective it is to resolve the issue.
  3. Improved Testing efficiency: Testing takes up a significant portion of the overall development lifecycle. Even the slightest improvement of the overall efficiency can make an enormous difference to the entire timeframe of the project. Although the setup time takes longer initially, automated tests eventually take up a significantly lesser amount of time. They can be run virtually unattended, leaving the results to be monitored toward the end of the process.
  4. Better ROI: while the initial investment may be on the higher side, automated testing saves organizations many a lot of money. This is due to the drop in the amount of time required to run tests, which leads to a higher quality of work. This in turn decreases the necessity for fixing glitches after release, thereby reducing project costs.
  5. Higher test coverage: In test automation, a higher number of tests can be executed about an application. This leads to higher test coverage, which is a manual testing approach that would imply a massive team, limited heavily with their amount of time. An increased test coverage leads to testing more features and a better quality of the application.
  6. Reusability of automated tests: The repetitive nature of test cases in test automation helps software developers to assess program reaction, in addition to the relatively easy configuration of their setup. Automated test cases can be utilized through different approaches as they are reusable.

#devops #testing #software testing #framework #automation testing #mobile app testing #test framework

Aarna Davis

Aarna Davis

1625217856

Top Software Testing/ QA Company | Software Quality Assurance Services

We are a top-rated software quality assurance & testing company leveraging our potential to profound expertise in delivering quality tested applications to businesses.

In the past 16 years, we have delivered over 4200 quality-assured software to a global clientele catering to various industries such as healthcare, adtechs, eLearning, and more.

Planning to outsource software QA services? Or would you like to hire an offshore software testing team?

Visit: https://www.valuecoders.com/software-quality-assurance-testing-services-company

#software quality assurance testing services #software quality assurance services #quality assurance testing services #quality assurance software testing company #quality assurance software testing

Ahebwe  Oscar

Ahebwe Oscar

1623185400

Permissions in Django Rest Framework

This article looks at how permissions work in Django REST Framework (DRF).

Objectives

By the end of this article, you should be able to explain:

  1. How DRF permissions work
  2. The similarities and differences between has_permission and has_object_permission
  3. When to use has_permission and has_object_permission

DRF Permissions

In DRF, permissions, along with authentication and throttling, are used to grant or deny access for different classes of users to different parts of an API.

Authentication and authorization work hand in hand. Authentication is always executed before authorization.

While authentication is the process of checking a user’s identity (the user the request came from, the token that it was signed with), authorization is a process of checking if the request user has the necessary permissions for executing the request (are they a super user, are they the creators of the object).

The authorization process in DRF is covered by permissions.

#permissions in django rest framework #django rest framework #permissions #rest #rest framework #django

Aarna Davis

Aarna Davis

1623402925

India's Top Software Quality Assurance & Testing Services

We are a top-rated software quality assurance & testing company leveraging our potential to profound expertise in delivering quality tested applications to businesses.

In the past 16 years, we have delivered over 4200 quality-assured software to a global clientele catering to various industries such as healthcare, adtechs, eLearning, and more.

Planning to outsource software QA services? Or would you like to hire an offshore software testing team?

#quality assurance professionals #quality assurance testing #quality assurance software testing #software testing and quality assurance