Skip to main content

Posts

Showing posts from June, 2022

BDD (2) — Cucumber & Gherkin.

In our previous post  Behavior Driven Development  we discussed BDD. Here, let's look at  Cucumber.  The flagship BDD framework for java, but not limited to Java. Why Cucumber As we saw in the previous post, until the Automation phase, BDD is all about discovering and formulating  behavioral scenarios  through collaboration. Its the automation phase, where things really happen. It would be easy if we could write these behavioral scenarios in plain English ( or another preferred spoken language ) and runtime could understand and execute those for us. This is where Cucumber comes to the rescue. Cucumber Cucumber is a framework that let us write application-behavioral-expectations in meaningful spoken-language-text using  Gherkin. Cucumber implementations are available in many programming languages as shown below. Courtesy — Cucumber.io supported programming languages NOTE: It's recommended (not mandatory) to choose an implementation for the same platform or programming language a

BDD Series (3) — Anatomy of a feature-file

In  previous post  we had an overview of the Cucumber, Gherkin & feature file. Now let's see how to write test cases in feature files using Gherkin. Anatomy of a feature-file All non-blank lines in a  feature file  have to start with a valid  Gherkin keyword.  Some of them we discussed in the previous post. Here is the description of the main Gherkin keywords. Feature: The first Keyword in feature-file must be  Feature,  it must be followed by   : After  Feature:  cucumber ignores all the text and lines for processing until a line starting with either  Scenario ,  Background,  or  Scenario Outline  keyword is found. All the text in between is used only for reporting purposes.  The first line is used as the feature name, and the remaining lines (if present) are used as feature descriptions. Scenario: Scenario keyword must also be followed by  :  .  Any text after  :  in this line, is used for reporting purposes. Steps: “Steps” is not a Gherkin keyword but it's an integral co

Java extension mechanism — Self-discovery & bean instantiation

In the Java world, libraries are created to separate the code for cross-cutting-concerns and packaged inside jars. If a project declares these libraries as  Maven  or  Gradle  dependencies, it can use the functionality provided by the library  as-is . What if, the project does want to use the library functionality, but with a small change in some behavior out of full functionality? While designing the library, programmers carefully decide what behaviors can be modified. These small behavior changes are called extensions. It  can not be achieved if  the library is not coded to accommodate extensions. In this post, we will see,  How to create extensible libraries . (SPI)  Service Provider Interface  Pattern. A Service is a set of Interfaces and a ServiceProvider is the concrete implementation of a Service. The service provider can be loaded at runtime by adding them to the application’s classpath. ServiceLoader Java-1.6 exposed a final & Iterable class  ServiceLoader .  This class