Sunday, March 3, 2024

AI In Software Testing

!pip install openai -q

from openai import OpenAI

OpenAI.api_key = '<api_key>'

client = OpenAI(api_key=OpenAI.api_key)

It is pretty simple as this below 


def generate_test_cases(requirement):

    response = client.chat.completions.create(

      model="gpt-3.5-turbo",

      messages=[

        {"role": "system", "content": "You are a helpful assistant capable of generating software test cases."},

        {"role": "user", "content": requirement}

      ]

    )

    return response.choices[0].message.content

requirement = "The system shall allow users to securely login with a username and password."

test_cases = generate_test_cases(requirement)

print(test_cases)


The messages has to be passed in the dictionary and the rest will be taken care automatically! 


References: 

https://drlee.io/implementing-ai-in-software-testing-creating-a-text-generation-model-for-test-automation-7294b26f93c4

No comments:

Post a Comment