Showing posts with label Test. Show all posts
Showing posts with label Test. Show all posts

JMeter Intro

0

Category : ,

How to run JMeter:

  • 1) Download JMeter Archive,
  • 2) Unzip the archive,
  • 3) Run jmeter executable in bin/ folder. Executable extensions depends on OS (.bat for Windows, .sh for Linux / MaC)
  • 4) JMeter should launch the UI!

Create Request

1)Add http Headers ie Sampler

Right-click on the TestPlan Add->Config Element->Http Header Manager

Add necessary http headers.

2) Create a ThreadGroup by right clicking on the Test Plan

Right-click on the TestPlan Add -> Threads (users) -> Thread Group.

The ThreadGroup is a container for the logic which will be run by a user thread.

3)Add http Request

Right-click on the ThreadGroup, then select Add -> Sampler -> Http Request.

Add server name, http method, path and parameters etc here

4) Add results viewers ie listeners

Add->Listener->View Results Tree
Add->Listener->Graph Results
Click on the Play button to run.

Graph Analysis

At the bottom of the graph, there are the following statistics, represented in colors:

  • Black: The total number of current samples sent.
  • Blue: The current average of all samples sent.
  • Red: The current standard deviation.
  • Green: Throughput rate that represents the number of requests per minute the server handled

The Throughput is the most important parameter. It represents the ability of the server to handle heavy load. The higher the Throughput is, the better is the server performance.

The deviation is shown in red - it indicates the deviation from the average. The smaller the better.
https://www.guru99.com/jmeter-performance-testing.html



Analyze the results
https://octoperf.com/blog/2017/10/19/how-to-analyze-jmeter-results/

my thanks to these awesome sites:
https://www.guru99.com/jmeter-element-reference.html
https://octoperf.com/blog/2018/03/29/jmeter-tutorial

Different Testing Types

0

Category :

  • Unit test: Specify and test one point of the contract of single method of a class. This should have a very narrow and well defined scope. Complex dependencies and interactions to the outside world are stubbed or mocked.

  • Integration test: Test the correct inter-operation of multiple subsystems. There is whole spectrum there, from testing integration between two classes, to testing integration with the production environment.

  • Smoke test (aka Sanity check): A simple integration test where we just check that when the system under test is invoked it returns normally and does not blow up. It is an analogy with electronics, where the first test occurs when powering up a circuit: if it smokes, it's bad.

  • Regression test: A test that was written when a bug was fixed. It ensures that this specific bug will not occur again. The full name is "non-regression test". It can also be a test made prior to changing an application to make sure the application provides the same outcome.

  • Acceptance test: Test that a feature or use case is correctly implemented. It is similar to an integration test, but with a focus on the use case to provide rather than on the components involved.

  • System test: Tests a system as a black box. Dependencies on other systems are often mocked or stubbed during the test (otherwise it would be more of an integration test).

  • Pre-flight check: Tests that are repeated in a production-like environment, to alleviate the 'builds on my machine' syndrome. Often this is realized by doing an acceptance or smoke test in a production like environment

  • Black-box testing: testing only the public interface with no knowledge of how the thing works.

  • Glass-box testing: testing all parts of a thing with full knowledge of how it works.




  • my thanks to the following answers:
    https://stackoverflow.com/questions/520064/what-is-unit-test-integration-test-smoke-test-regression-test?rq=1
    https://stackoverflow.com/questions/437897/what-are-unit-testing-and-integration-testing-and-what-other-types-of-testing-s

    Asynchronous requests with Postman's PM API

    0

    Category : , , ,

    You can send requests asynchronously with the pm API method sendRequest, these can be used in the pre-request or the test script.

    Its important to note that if you send an asynch request in the pre-request tab "The main Postman request will NOT be sent until the pre-request script is determined to be finished with all callbacks, including sendRequest."

    A blog post containing more detailed info on this can be seen on the below link:
    http://blog.getpostman.com/2017/10/03/send-asynchronous-requests-with-postmans-pm-api/

    I have only done basic testing with this but I could get the method to fire using the 2nd example of the 3 available on the previous url:
    var headers = ['reseller_id:' + environment.booking_api_reseller_id];
        headers.push('request_id:'+ environment.booking_api_request_id);
        headers.push('request_authentication:'+ environment.booking_api_request_authentication);
    console.log(headers);
    
    // Example with a full fledged SDK Request
    const echoPostRequest = {
      url: environment.booking_api_host + '/v1/Availability/product/' + environment.booking_api_availability_productKey + '?fromDateTime=' + environment.booking_api_availability_start_date + 
            '&toDateTime=' + environment.booking_api_availability_end_date,
      method: 'GET',
      header: headers,
      body: {
        mode: 'raw',
        raw: JSON.stringify({ key: 'this is json' })
      }
    };
    
    pm.sendRequest(echoPostRequest, function (err, res) {
        console.log('..............here........');
        console.log(err ? err : res.json());
    });
    
    
    I was having issues passing the headers to the request but i found the below url which states the header param should be an array.
    http://www.postmanlabs.com/postman-collection/Request.html#~definition

    Reuseable scripts in Postman

    0

    Category : , , ,

    You can reuse methods across requests in postman.

    Tip #5 in the below list:
    http://blog.getpostman.com/2017/07/28/api-testing-tips-from-a-postman-professional/

    1. Init in Pre-Request or Tests tab or in a previous request.
    2. Store in an Environment or Global variable.
    3. Then call multiple times from other requests.
    1) Setup method in Pre-Request or Tests tab in Postman, you can also list params to pass to method.
    postman.setEnvironmentVariable("commonTests", (responseBody, environmentSchema) => {
        
        // parse response and log
        var responseObject = JSON.parse(responseBody);
        //console.log("response: " + JSON.stringify(responseObject));
    
        // test to check status code
        tests["Status code is 200"] = responseCode.code === 200;
        
        // test response time
        console.log("responseTime: " + responseTime);
        tests["Response time is less than " + environment.max_server_response_time + "ms"] = responseTime < environment.max_server_response_time;
        
        // validate schema
        eval(environment.validateSchema)(responseObject, environmentSchema);
    });
    

    2) Call method from the Pre-Request or Tests tab in Postman.
    You can also call methods from within another method as you can see at the end of the previous code sample.
    
        // validate schema
        eval(environment.commonTests)(responseObject, environment.specificSchema);
    

    Automate Postman Tests with Newman

    0

    Category : , , ,

    Newman is a command-line collection runner for postman.

    1) So the first step is to export your collection and environment variables.

    2) Save the JSON file in a location you can access with your terminal.

    3) Install Newman CLI globally, then navigate to the where you saved the collection.

    4) Once you are in the directory, run the below command, replacing the collection_name with the name you used to save the collection.
    newman run "collection_name.json" -e GITHUB_ENV.postman_environment.json
    
    5) Ensure you add the -e flag which is for the environment param.

    6) You may also want to specify the -d flag for a data file and the --insecure switch to allow calls to self signed certs.


    You should see something like the below:





    my thanks to the great article below.
    https://scotch.io/tutorials/write-api-tests-with-postman-and-newman#newman-cli

    Postman BDD allows you to use BDD syntax to structure your tests and fluent Chai-JS syntax to write assertions. So the above test suite could look like this instead:
    https://github.com/BigstickCarpet/postman-bdd

    API Test Automation CI using GitHub, Jenkins, and Slack

    First few steps are the same as above i.e. export the postman tests and environment.

    Probably start at Step 2: Setup Your Jenkins Build

    npm commands

    Get npm installed version
    npm -version
    
    Get npm installion directory
    npm root -g
    
    Get list of installed packages
    npm list -g --depth=0
    


    my thanks to the great post below:
    https://www.linkedin.com/pulse/api-test-automation-ci-using-github-jenkins-slack-talal-ibdah?trk=mp-reader-card

    Postman Intro

    1

    Category : , ,

    Postman is an app that we use for testing during our API development. Basically sending requests to our API dev project to test responses and functionality.

    Postman docs are available here: Postman Docs

    The docs also contain a couple of videos to get you up-and-running and there is a youtube channel: Postman How-to Series

    Basic Usage

    You can send most request method types using Postman, including Query string params, request body info, headers containing authentication info and retrieve/view responses in any format, we predominantly worked with JSON on our API. You can also work with cookies but we have not used this yet.

    Extracting data from responses and chaining requests

    You can extract data from response and chain requests using test scripts.

    1) Sett up a new environment with variables.
    2) Create environment variable to store data and allow multiple requests to access data.
    3) set value for new variable and then access with next request.
    // set Environment Variable
    var jsonData = JSON.parse(responseBody);
    postman.setEnvironmentVariable("token", jsonData.token);
    
    // access in request body
    {
       "data" : {
               "status": "my_status",
               "token": "{{token}}"
       }
    }
    
    There is another helpful blog post on this here

    Explanation Of API Chaining

    Creating cURL commands in Postman

    To create a cURL command in Postman.

    Testing in Postman

    We can write tests to validate the schema returned in response and various errors that are expected.
    // parse response
    var jsonData = JSON.parse(responseBody);
    
    // create schema
    var schema = 
    {
        "type": "object",
        "properties":  {
                        "data": {
                            "type": "object",
                            "properties": {
                                            "reservationReference": {"type": "string"}
                                            }
                                }
                        }
    };
    
    // validate schema
    tests["Valid Response Schema"] = tv4.validate(jsonObject, schema);
    

    Postman Sandbox

    The Postman Sandbox is a JavaScript execution environment that is available to you while writing pre-request scripts and test scripts for requests (both in Postman and Newman). Whatever code you write in the pre-request/test script section is executed in this sandbox.

    JSON Schema Validation

    Tiny Validator for JSON Schema v4
    JSON Schema Examples
    Understanding json schemal


    my thanks to this great blog post:
    http://www.tjmaher.com/2016/07/introduction-to-api-testing-with.html