Showing posts with label Testing. Show all posts
Showing posts with label Testing. Show all posts

Tuesday, November 23, 2021

Contract Testing

 Contract testing is a methodology for ensuring that two separate systems (such as two microservices) are  compatible and are able to communicate with one other.

 It captures the interactions that are exchanged between each service, storing them in a contract, which can then be used to verify that both parties adhere to it.

Contract testing goes beyond schema testing, requiring both parties to come to a consensus on the allowed set of interactions and allowing for evolution over time.

Pact is a code-first consumer-driven contract testing tool, and is generally used by developers and testers who code. The contract is generated during the execution of the automated consumer tests.

A major advantage of this pattern is that only parts of the communication that are actually used by the consumer(s) get tested. 

This in turn means that any provider behaviour not used by current consumers is free to change without breaking tests.

Tuesday, October 6, 2020

WebDriverIO Introduction

Webdriver.io is a mobile and browser test automation framework that has recently become quite popular in the software testing industry. 

This free and open-source framework is written in JavaScript and runs on Node.js. Packaged into npm, WebdriverIO is easy to install and use. This framework enables you to test web applications as well as native mobile apps.

Webdriver is popular because it is backed by Selenium which means you can run test scripts on all browsers. While it brings all the advantages of Selenium, it eliminates the pain of writing Java-based scripts.

 It allows you to easily integrate it with multiple testing frameworks such as Appium to bring the best out of both worlds.

The Key Features of WebDriverIO:

  • Run automation tests both for web applications as well as native mobile apps
  • Simple and Easy Syntax
  • Integrating tests to third-party tools such as Appium.
  • ‘Wdio setup wizard’ to make the setup simple and easy.
  • Integrated test runner

WebDriverIO Vs Selenium WebDriver

Both WebDriverIO and Selenium WebDriver are open source and are used for browser testing. Selenium is used for automating browsers, while WebDriverIO is used for automating both browsers and native mobile apps.

Prerequisites For Setting Up WebDriverIO

  • You need to install NodeJS in your machine before setting up WebDriverIO.
  • Additionally, you’ll need to install VSCode IDE
  • To install WebDriverIO CLI, execute the below command in the terminal.      npm i --save-dev @wdio/cli


Monday, August 31, 2020

Introduction to Junit5

 JUnit5 is the next generation of JUnit. The goal is to create an up-to-date foundation for developer-side testing on the JVM. This includes focusing on Java 8 and above, as well as enabling many different styles of testing.

JUnit 5 is split into three sub-projects: Jupiter, Vintage, and Platform.

They communicate via published APIs, which allows tools and libraries to inject customized behavior. Then, each sub-project is split into several artifacts to separate concerns and guarantee maintainability.

JUnit Vintage:

Implements an engine that allows to run tests written in JUnit 3 and 4 with JUnit 5.

JUnit Jupiter is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5. 



Required Dependencies:

The junit-jupiter-api (version 5.4.2):This dependency provides the public API for writing tests and extensions.

The junit-jupiter-engine (version 5.4.2):This dependency contains the implementation of the JUnit Jupiter test engine that runs our unit tests.

Configuring the Maven Surefire Plugin:

build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-surefire-plugin</artifactId>

            <version>2.22.1</version>

        </plugin>

    </plugins>

</build>            

Note: First, if we want to use the native JUnit 5 support of the Maven Surefire Plugin, we must ensure that at least one test engine implementation is found from the classpath. 

That’s why we added the junit-jupiter-engine dependency to the test scope.


Mockito

 Mockito is a mocking framework. It is a Java-based library used to create simple and basic test APIs for performing unit testing of Java applications. It can also be used with other frameworks such as JUnit and TestNG.

The framework allows the creation of test double objects (mock objects) in automated unit tests for the purpose of test-driven development (TDD) or behavior-driven development (BDD).

Mockito allows developers to verify the behavior of the system under test (SUT) without establishing expectations beforehand.One of the criticisms of mock objects is that there is a tight coupling of the test code to the system under test.

Benefits of Mockito:

  • No Handwriting − No need to write mock objects on your own.
  • Refactoring Safe − Renaming interface method names or reordering parameters will not break the test code as Mocks are created at runtime.
  • Return value support − Supports return values.
  • Exception support − Supports exceptions.
  • Order check support − Supports check on order of method calls.
  • Annotation support − Supports creating mocks using annotation.

Following are the mock() methods with different parameters:

mock() method with Class: It is used to create mock objects of a concrete class or an interface. It takes a class or an interface name as a parameter.
Syntax: <T> mock(Class<T> classToMock)

mock() method with Answer: It is used to create mock objects of a class or interface with a specific procedure. It is an advanced mock method, which can be used when working with legacy systems. It takes Answer as a parameter along with the class or interface name. The Answer is an enumeration of pre-configured mock answers.
Syntax: <T> mock(Class<T> classToMock, Answer defaultAnswer)

mock() method with MockSettings: It is used to create mock objects with some non-standard settings. It takes MockSettings as an additional setting parameter along with the class or interface name. MockSettings allows the creation of mock objects with additional settings.
Syntax: <T> mock(Class<T> classToMock, MockSettings mockSettings)

mock() method with ReturnValues: It allows the creation of mock objects of a given class or interface. Now, it is deprecated, as ReturnValues are replaced with Answer.
Syntax: <T> mock(Class<T> classToMock, ReturnValues returnValues)

mock() method with String: It is used to create mock objects by specifying the mock names. In debugging, naming mock objects can be helpful whereas, it is a bad choice using with large and complex code.
Syntax: <T> mock(Class<T> classToMock, String name)


ES12 new Features