Skip to main content

AI automated test generation

Project description

test-ai-leds is the python package that powers the Test.AI VS code extension

Test.AI Extension for VS Code

Test.AI is a powerful Visual Studio Code extension designed to simplify the process of creating Behavior-Driven Development (BDD) tests for software. By leveraging generative AI and agents, Test.AI converts .andes files into Gherkin .feature files and auto-generates corresponding step definitions. This automation significantly reduces the time and effort required to develop comprehensive BDD tests.

Features

  • Conversion of .andes Files to Gherkin: Automatically transforms user stories described in .andes files into Gherkin .feature files.
  • Step Definition Generation: Generates step definitions for the .feature files to streamline test development. Currently, step definitions are generated exclusively for C#, with plans to support additional languages in the future.
  • Unit Test Generation: Automatically generates unit tests in C#, providing structured and reusable test cases for your codebase.
  • AI-Powered Automation: Utilizes large language models (LLMs) to ensure high-quality and context-aware test generation.
  • Seamless Integration: Works directly within Visual Studio Code, providing a smooth development experience.

Important Project Structure Requirement

For unit test generation and test-related file discovery, all source code files must be inside a src/ folder. The AI-based system searches for relevant files starting from src/, so ensure that your project follows this structure:

project-root/
  ├── src/
  │    ├── your_code/
  │    ├── another_folder/
  │    ├── ...
  ├── tests/
  ├── README.md
  ├── other_files

Any class intended for unit test generation must reside within a subfolder inside src/.

Installation

  1. Open Visual Studio Code.
  2. Go to the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of the window or pressing Ctrl+Shift+X.
  3. Search for Test.AI.
  4. Click Install.

Getting Started

Prerequisites

  • Python
  • Python package test-ai-leds
  • .andes files describing user cases in the expected format.
  • An active internet connection for AI-based generation.
  • A .env file in the root folder of your VS Code project containing the following variables:
    • DTO_SOURCE: The full path to the DTO files directory in your project.
    • SWAGGER_PATH: The full path to the Swagger document of your project.
    • LLM_MODEL: The AI model chosen by the user.
    • API_KEY: The API key for the AI model being used.

Setup

First you need to install test-ai-leds by running pip install test-ai-leds in the terminal. You can either install globally or in a virtual environment.

It is also necessary to add the Python package scripts directory to the PATH environment variable. Below is an explanation of how to do this:

  • Windows:

    • Run pip show test-ai-leds in the terminal.
    • Some information will be returned, including the location of the installed packages. It will look something like: C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages
    • You just need to change the last directory from site-packages to Scripts. For example: C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts
    • Add this path to your environment variables.
    • Note: The same can be done using Python virtual environments if you do not want to install the library globally. In that case, the Scripts path will be relative to the venv folder.
  • Linux:

    • Linux does not allow global installations of Python packages. Therefore, you need to create a virtual environment using the command:
      python -m venv <venv_name>
    • Activate the venv with:
      source <path_to_venv>/bin/activate
    • Run: pip install test-ai-leds
    • The scripts path on Linux is usually: <path_to_venv>/bin
    • Run: nano ~/.bashrc and add the following at the end of the file: export PATH=$PATH:/<path_to_your_venv>/bin
    • Finally, run: source ~/.bashrc to apply the changes.

Usage

  1. Open a .andes file in Visual Studio Code.
  2. Right-click on the file and select Generate BDD Tests with Test.AI.
  3. The extension will:
    • Create a corresponding .feature file in the same directory.
    • Generate step definitions and save them in a designated folder (steps/ by default).
    • Generate unit tests for relevant classes inside src/.
  4. Review and refine the generated tests as needed.

Example

Input (example.andes):

[User Story]
As a user, I want to log in to my account so that I can access my dashboard.

[Acceptance Criteria]
- Given I am on the login page
- When I enter my username and password
- And I click the login button
- Then I should see the dashboard.

Output (features/example.feature):

Feature: User Login

  Scenario: Successful login
    Given I am on the login page
    When I enter my username and password
    And I click the login button
    Then I should see the dashboard.

Generated Step Definitions (steps/exampleSteps.cs):

using TechTalk.SpecFlow;

[Binding]
public class ExampleSteps
{
    [Given("I am on the login page")]
    public void GivenIAmOnTheLoginPage()
    {
        // Add implementation here
    }

    [When("I enter my username and password")]
    public void WhenIEnterMyUsernameAndPassword()
    {
        // Add implementation here
    }

    [When("I click the login button")]
    public void WhenIClickTheLoginButton()
    {
        // Add implementation here
    }

    [Then("I should see the dashboard")]
    public void ThenIShouldSeeTheDashboard()
    {
        // Add implementation here
    }
}

Happy Testing! 🚀

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

test_ai_leds-0.1.7.1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

test_ai_leds-0.1.7.1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file test_ai_leds-0.1.7.1.tar.gz.

File metadata

  • Download URL: test_ai_leds-0.1.7.1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for test_ai_leds-0.1.7.1.tar.gz
Algorithm Hash digest
SHA256 b37f2ca2da34c8732a2e58c47e8d1f89fbf484d8be2ec793ea8e6923ec06c058
MD5 06b44d059aea7820e9194387fbe057f0
BLAKE2b-256 058534e9d74fc46a5be0873cfb360abade796ae4954a581c655137f0e1dd752d

See more details on using hashes here.

File details

Details for the file test_ai_leds-0.1.7.1-py3-none-any.whl.

File metadata

  • Download URL: test_ai_leds-0.1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for test_ai_leds-0.1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab1b68cf2d52f0f6245e47ab4d30c5a1a6362dad47a4adcf4fdd407c6f59ab38
MD5 3b271c8c6c0a00420b835efe612fec88
BLAKE2b-256 4e1dcdadb321c536d6aee29180ad8b5b26929d78d018b9c8ddb4a3ea22e6e032

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page