What is Model-Based Testing ?
fb.com/testingtrends

What is Model-Based Testing ?

MBT is where you create a mockup of the system being tested, along with a way to generate random, yet realistic, test data. The mockup’s job is to try to produce the same output as the actual system. Then the two outputs are compared.

Differences mean one of two things:

1. The model needs to be updated.

2. The actual system isn’t behaving as expected.

Let’s take a look at a simple example to further describe this.

Building the Data Generator

Having good test data is the first half of this method. But we also don’t want the effort to be spent creating a bunch of data sets. Instead, let’s make a data generator. The generator’s job will be to make data that the system would expect. It can’t be gibberish, otherwise we’ll be using a bunch invalid data, hence the “random yet realistic” description before.

Let’s say your system expects a person record in JSON format, with a name, address, city, state and ZIP code. The generator would then create valid JSON, but could choose to include (or not) each piece of info. The generator can be created with a switch statement, along with picking random values out of arrays of data (state, names, ZIP codes, etc.).

 Building the Model 

For the data generator example above, let’s say the system checks to see that a valid person record was provided, in the following ways:

1. Accept names less than or equal to 50 characters.

2. Accept addresses less than or equal to 35 characters.

3. Accept valid combinations of city, state, ZIP.

4. Throw appropriate error for any other case.

 Even if the system doing these checks is actually a collection of small microservices, that’s fine. A model can be built fairly simply, and take the form of a single if/else statement. 

Comparing Results 

The final step is comparing the outputs of the model versus the system. If you gave a record with a city of St. Louis, and a ZIP code of 00000 (which is invalid), an accurate model would expect an error. If the actual system doesn’t, then you may have a bug.

It’s possible to also create a kind of heatmap to see which parts were different when they were compared. Then, as dozens or hundreds of comparisons start showing a common theme of the city and ZIP code being involved, the more apparent it’ll become that something weird is happening in that logic.

 Advantages and Tips

The biggest advantage to this approach is that the more complex the system is, the better. The chances of both the model and the system being wrong in the exact same way are near impossible, so you have a much greater assurance that a zero-difference comparison means that that part of the system is behaving correctly.

Plus, because your model and generator can each live in a giant program, you can use something like Cucumber to generate code for you. This makes understanding the code—along with the maintenance—much easier, since you can read exactly what the code will be doing.

To view or add a comment, sign in

More articles by Sandeep Sahu

  • GenAI-Powered Environment Setup related QA's

    Question 1. Which of the following best describes how Generative AI supports environment setup? It tracks code changes…

  • GenAI-Powered Test Planning

    Question 1. Which of the following best describes the role of Generative AI in test planning? It generates final user…

  • Assessment for Test Design and Data Preparation with GenAI

    Question 1. What is one of the key roles of GenAI in test planning? Generating release notes Running batch jobs…

  • Assessment for Foundations of Generative AI in Software Testing

    Q 1 What is the core purpose of software testing? To generate UI designs To create complex source code To compress…

  • Microsoft Azure Fundamentals

    Microsoft Azure is a cloud computing platform with an ever-expanding set of services to help you build solutions to…

  • Agile Testing

    Agile Testing, a contemporary approach to software testing, is an integral part of the Agile methodology. This…

  • Chatbot Testing | How To Test A Chatbot

    What is Chatbot A chatbot is a piece of software designed to simulate conversation with human users. They are often…

  • Banking Domain Knowledge for Testers

    What is Domain? It is an area, IT industry point view it is project’s business area, example: BFSI, ERP, ECommerce…

  • RESTful Web Services

    What is REST? Representational State Transfer otherwise REST is an architectural style for providing standards between…

  • Part-2 SOAP Web Services

    What is Web Service ? A web service is essentially a collection of open protocols and standards used for exchanging…

Others also viewed

Explore content categories