Test Driven Development: Intelligent Data Types – JBehave Examples

Intelligent Data

Test driven development is a software design approach in which tests are written before the code itself, ensuring robust and reliable functionality. JBehave, a flexible Java-based framework, supports both Behavior-Driven Development (BDD) and TDD methodologies, making test automation accessible and intuitive. This framework allows developers to create intelligent data types in BDD, which can be passed as actionable parameters in the code to enhance software quality assurance.

JBehave Examples and Data Interpretation

Using BDD-driven testing with JBehave, you can process multiple data types efficiently. For instance:

  • Create a Facebook test account and pass a test mail ID through a Facebook parameter.
  • Strip domains from email IDs to create test emails in YOPmail.
  • Handle multiple data types such as strings, dates, and numeric values.
  • Read JSON/XML from a RESTful API and create an object hierarchy.

For example, consider a scenario that selects the lowest-priced quote from multiple files in a folder and then places an order:

1
2
3
4
5
6
7
8
Scenario: Select and purchase least pricey quote
   Given that user has quotations in the folder <quotation>
   When user selects least cost quote
   Then this least cost quote should come by default when creating a purchase order.
   Examples
   |quotation|
   |/WasherQuote/|
   |/PaintQuote/|

Table 1 – The story

Since the focus is on intelligent data types in BDD, we will focus on the Given statement, reading quotations into a list using our custom data type.

1
2
3
4
5
6
@Given("that user has quotations in the folder <quotation>")
public void readQuotation(@Named("quotation") Quotations quotationMap)
	{
          quotationMap.quotes(1).VendorName
		// opens web URL
	}
  

Table 2 – The code behind

JBehave maps the Given step in the story to the code-behind method and passes the value <quotation> from the story file to the Java code. This demonstrates how JBehave supports test driven development with intelligent data types.

Startup and Registering Custom Parameter Converters

At startup, JBehave calls the configuration() method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@Override
public Configuration configuration() {
     Configuration configuration = new MostUsefulConfiguration()
            .useParameterConverters(
                    new ParameterConverters().addConverters(customConverters()));
    return configuration;
}

private ParameterConverter[] customConverters() {
List<ParameterConverter> converters = new ArrayList<ParameterConverter>();
converters.add(new QuotationsConverter()); // custom number format
return converters.toArray(new ParameterConverter[converters.size()]);
}

Table 3 – Registering the parameter converter

Here, we register custom parameter converters, including QuotationsConverter. Using a List is convenient for manipulation before converting to an array. The addConverters() method registers this array with JBehave, allowing our custom converter to be recognized.

Declaring the QuotationsConverter Class

The QuotationsConverter class implements the ParameterConverter interface:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public class QuotationsConverter implements ParameterConverter {

public boolean accept(Type type) {
if (type instanceof Class<?>) {
return Quotations.class.isAssignableFrom((Class<?>) type);
}
return false;
}

public Object convertValue(String value, Type type) {
Quotations Quotations = new Quotations();
 // Read folder in value and populate quotations

Quotations.addQuotes(// List from above);
return Quotations;
}
}

Table 4 – Declare the parameter converter

The accept() method ensures JBehave recognizes the type, while convertValue() reads the folder and converts the data into a Quotations object. This object is then passed to the quotationMap in the code-behind, enabling testers to leverage behavior-driven testing effectively.

Automation Testing: Are You Ready to Start

Evaluate your automation readiness with Are You Ready to Start? — a practical guide to avoiding common pitfalls, scaling smart, and making automation work for your team.

Sequence of Steps Followed by JBehave

Next, let’s review the sequence for how JBehave supports test driven development with intelligent data types:

  1. JBehave calls configuration() at startup.
  2. All parameter converters, including custom converters, are registered.
  3. For each scenario, steps are read from the story and executed.
  4. JBehave maps each story step to the corresponding code-behind step.
  5. Parameter values are read into memory.
  6. On encountering @Named, the value is retrieved from memory.
  7. The value is checked against the expected parameter type.
  8. The accept() method of the registered converter is called.
  9. If accepted, convertValue() returns the parameter object.
  10. The returned object is assigned to the variable in the code-behind and used for logic execution.

Benefits of Using JBehave with Intelligent Data Types

By combining TDD methodology with intelligent data types:

  • Test coverage becomes more comprehensive.
  • Scenarios are easier to manage across multiple data types.
  • Code readability and maintainability improve.
  • QA engineers can execute BDD scenarios with precision.
  • Integration with automated pipelines is simplified.

JBehave is a powerful tool for implementing test driven development, especially when using intelligent data types in BDD.

Frequently Asked Questions (FAQs)

What is test driven development (TDD)?

TDD is a software design approach where tests are written before the code to ensure functionality, reliability, and maintainability.

How does JBehave support TDD?

JBehave allows BDD-style scenarios to be linked to code-behind methods, ensuring tests drive development.

What are intelligent data types in BDD?

They are custom data types passed as parameters to code, enabling complex test data handling in BDD frameworks.

How to integrate intelligent data types in JBehave?

Declare a parameter class, create a converter, register it in configuration, and use it in the code-behind.

Can JBehave handle multiple data types in a single test scenario?

Yes. Strings, dates, numbers, JSON, XML, and other types can be processed using custom converters.

Why use TDD methodology with intelligent data types?

It improves test coverage, reduces errors, enhances maintainability, and ensures QA precision for complex applications.

Logo Colour

Sign up to receive notifications when we post our next article, and stay OnPath with good QA practices.

Written by

Picture of OnPath Staff
OnPath Staff
The OnPath Staff is a mix of test engineers, marketers, and managers united by an interest in sharing useful QA insights clearly. What unites us isn’t just an interest in software quality, but a love for learning, collaborating, and making software a little bit better, every day.
Picture of OnPath Staff
OnPath Staff
The OnPath Staff is a mix of test engineers, marketers, and managers united by an interest in sharing useful QA insights clearly. What unites us isn’t just an interest in software quality, but a love for learning, collaborating, and making software a little bit better, every day.

Related content

you-x-ventures-Oalh2MojUuk-unsplash

The Benefits of Behavior-Driven Development in Agile Development

In modern agile development, cross-functional communication is critical to delivering high-quality software. As sprint cycles shorten and releases become more frequent, teams must collaborate...

performance-featured

Automated Testing Tools: First Steps with the Capybara Testing Tool

Capybara is one of the widely used automated testing tools that acts as an effective wrapper for web drivers like Selenium, Webkit, Rack Test...

The Test Pyramid in 2026: Still Relevant, Still Necessary

Organizations are pushing hard to accelerate AI-assisted software delivery. Cloud-native applications scale up and down in real time. Mobile-first platforms are no longer optional....

Logo Colour

Get notified when we post our next article!

document.addEventListener("DOMContentLoaded", function () { var shareMailBtn = document.getElementById('shareMail'); if (!shareMailBtn) return; shareMailBtn.addEventListener('click', function (e) { e.preventDefault(); const subject = encodeURIComponent(document.title); const body = encodeURIComponent( `Hi, I came across this article on OnPath Testing and thought it would be worth sharing with you. ${window.location.href} Hope you find it useful. Best regards,` ); window.location.href = `mailto:?subject=${subject}&body=${body}`; }); });