Modernization with IBM Power

Modernization with IBM Power

Connect, learn, share, and engage with IBM Power.

 View Only

Legacy modernization using AI/ML - AI driven Test automation

By RajKumar Chindanuru posted Mon April 14, 2025 11:54 PM

  

From my previous blog post – “After code rewrite, manually testing IBM i applications can be time-consuming and prone to human error. AI-driven test automation can streamline the testing process by automatically generating test cases, identifying defects, and executing regression tests with minimal manual intervention. For example, An AI-powered testing framework automatically generates test scripts for different RPG programs, execute the testcases to validate after code changes.”

That’s exactly the topic we discuss in this blog post. For manual testing of IBM i applications, it mostly requires deep domain knowledge, step-by-step validation, and coordination between business and IT teams. What if AI could take over this tedious process and accelerate the modernization efforts?

For example, let’s take a case where an RPG III program is rewritten in RPG IV or even converted business logic to a modern microservices-based architecture. Testing the updated logic across all scenarios is critical as:

  •          Test case preparation takes time
  •          Test data needs to be crafted carefully
  •          Regression testing must cover all impacted modules
  •          One missing test case can cause production issues

This is where AI-powered test automation can:

  •         Generate test cases based on program logic and historical input/output patterns
  •         Detect anomalies or potential defects post-code rewrite
  •         Run regression tests across dependent programs without manual setup

Consider scenarios for detecting duplicate records following the code rewrite process. Let’s say there is a customer master file CUSMAS, and we want to ensure no duplicate records are being introduced. Here AI can help:

  • To analyze historical data patterns and structure
  • To generate test data with potential duplicates
  • To execute tests against the modernized logic
  • To validate the system rejects or flags duplicates

Customer Master table definition

CREATE TABLE CUSMAS (

  CUST_ID CHAR(10),

  NAME VARCHAR(50),

  EMAIL VARCHAR(50),

  PRIMARY KEY (CUST_ID)

);

AI Simulation, generating potential test data using Python

import pandas as pd

from faker import Faker

import random

fake = Faker()

data = []

# Generate 10 unique customer records

for _ in range(10):

    cust_id = fake.unique.random_number(digits=5)

    data.append({

        "CUST_ID": str(cust_id),

        "NAME": fake.name(),

        "EMAIL": fake.email()

    })

# Introduce duplicates intentionally

duplicate = random.choice(data)

data.append(duplicate)  # 1 duplicate

data.append({

    "CUST_ID": duplicate["CUST_ID"],  # same ID

    "NAME": fake.name(),              # different name

    "EMAIL": duplicate["EMAIL"]       # same email

})

df = pd.DataFrame(data)

df.to_csv("ai_test_customers.csv", index=False)

print("Generated test file with duplicates.")

Python script to upload and validate Data

import ibm_db

import csv

conn_str = "database, host name and port details"

conn = ibm_db.connect(conn_str, "", "")

# Load test file and try to insert

with open('ai_test_customers.csv', newline='') as file:

    reader = csv.DictReader(file)

    for row in reader:

        sql = f"""

        INSERT INTO CUSMAS (CUST_ID, NAME, EMAIL)

        VALUES ('{row['CUST_ID']}', '{row['NAME']}', '{row['EMAIL']}')

        """

        try:

            ibm_db.exec_immediate(conn, sql)

        except Exception as e:

            print(f"Duplicate or error on CUST_ID {row['CUST_ID']}: {e}")

Similarly, multiple test scenarios can be constructed, and test cases can be produced for both the old and new versions of the software. Comprehensive reports can be generated showing test coverage and defects.

To conclude, testing becomes a bottleneck as more businesses modernize their IBM i applications. By adopting AI-driven test automation, organizations can significantly reduce manual effort, minimize human errors, and accelerate project timelines while ensuring legacy applications continue to perform reliably after modernization.

0 comments
3 views

Permalink