Skip to main content
Glama
felipeassis10

bdd-regression-test-generator

bdd-regression-test-generator

REST API エンドポイントと OpenAPI/Swagger サービス契約を解析して、以下を生成する自律エージェントです:

  • BDD Gherkin 仕様(.feature ファイル)。すべてのハッピーパスとエッジケースのシナリオを記述します。

  • TypeScript 回帰テストスクリプト(Jest + Playwright 対応)。実際のサービスに対してすぐに実行できます。

2つのインターフェースを提供します:

インターフェース

説明

CLI

bdd-gen generate --input <spec> --output <dir>

MCP Server

MCP 対応ホスト(例:IBM Bob、Claude Desktop)に公開可能な Model Context Protocol サーバー


機能

  • OpenAPI 3.x および Swagger 2.0 の契約(JSON または YAML)を解析します。

  • すべてのパス、HTTP メソッド、パラメータ、リクエストボディ、レスポンススキーマを抽出します。

  • エンドポイントのタググループごとに 1 つの .feature ファイルを生成します。

  • エンドポイントのタググループごとに、完全に型付けされた Jest テストケースを含む *.spec.ts ファイルを 1 つ生成します。

  • 生成時にカスタムベース URL の注入をサポートします。

  • MCP サーバーは analyze_contract、generate_gherkin、generate_tests の各ツールを公開します。


Related MCP server: Swagger Testcase MCP

インストール

npm install
npm run build

ビルド後にグローバル CLI として使用するには:

npm link

CLI の使用方法

# Generate both Gherkin and Jest tests from an OpenAPI YAML spec
bdd-gen generate --input ./petstore.yaml --output ./generated --baseUrl https://api.example.com

# Generate only Gherkin feature files
bdd-gen generate --input ./petstore.json --output ./generated --only gherkin

# Generate only Jest test scripts
bdd-gen generate --input ./petstore.json --output ./generated --only jest

# Analyze a contract and print a summary (no file generation)
bdd-gen analyze --input ./petstore.yaml

CLI オプション

オプション

エイリアス

説明

デフォルト

--input <path>

-i

OpenAPI/Swagger 契約ファイルへのパス

必須

--output <dir>

-o

生成されたファイルが書き込まれるディレクトリ

./generated

--baseUrl <url>

-b

生成されたテストファイルに埋め込むベース URL

http://localhost:3000

--only <type>

gherkin または jest のみを生成(両方の場合は省略)

両方

--verbose

-v

詳細ログを有効にする

false


MCP サーバー

以下のコマンドで MCP サーバーを起動します:

npm run mcp

サーバーは以下のツールを登録します:

analyze_contract

ファイルパスまたは生の JSON/YAML 文字列から OpenAPI/Swagger 契約を解析します。

入力:

{ "source": "./petstore.yaml" }

出力: パス、メソッド、パラメータ、スキーマを含む構造化された ContractSummary JSON オブジェクト。


generate_gherkin

解析された契約から Gherkin の .feature コンテンツを生成します。

入力:

{
  "source": "./petstore.yaml",
  "outputDir": "./generated"
}

出力: 書き込まれた .feature ファイルパスのリスト。


generate_tests

解析された契約から TypeScript の Jest テストスクリプトを生成します。

入力:

{
  "source": "./petstore.yaml",
  "outputDir": "./generated",
  "baseUrl": "https://api.example.com"
}

出力: 書き込まれた .spec.ts ファイルパスのリスト。


プロジェクト構造

bdd-regression-test-generator/
├── src/
│   ├── parser/
│   │   └── contract-analyzer.ts   # OpenAPI/Swagger parser and extractor
│   ├── generator/
│   │   ├── gherkin-builder.ts     # Gherkin .feature file builder
│   │   └── jest-builder.ts        # TypeScript Jest spec builder
│   ├── mcp/
│   │   └── server.ts              # MCP server exposing generation tools
│   └── cli.ts                     # Commander-based CLI entry point
├── tests/
│   └── generator.test.ts          # Unit tests for parser and generators
├── dist/                          # Compiled output (after build)
├── package.json
├── tsconfig.json
└── README.md

テストの実行

npm test

カバレッジ付き:

npm run test:coverage

例:生成された Gherkin

Feature: Pets

  Background:
    Given the API base URL is "https://api.example.com"

  Scenario: GET /pets - list all pets - success
    Given I have valid authentication credentials
    When I send a GET request to "/pets"
    Then the response status code should be 200
    And the response body should match the "PetList" schema

  Scenario: GET /pets - list all pets - unauthorized
    Given I have invalid or missing authentication credentials
    When I send a GET request to "/pets"
    Then the response status code should be 401

例:生成された Jest テスト

import axios from 'axios';

const BASE_URL = 'https://api.example.com';

describe('Pets', () => {
  describe('GET /pets', () => {
    it('should return 200 for a valid request', async () => {
      const response = await axios.get(`${BASE_URL}/pets`);
      expect(response.status).toBe(200);
    });
  });
});

ライセンス

MIT

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    An MCP server for the comprehensive analysis of Swagger 2.0 and OpenAPI 3.x contracts. It allows users to extract detailed information about endpoints, request/response schemas, parameters, and security configurations from API documentation.
    -
  • A
    license
    A
    quality
    F
    maintenance
    MCP server for API test case generation from Swagger/OpenAPI specs. Parses Swagger 2.0 and OpenAPI 3.x, generates test cases across 8 categories (positive, negative, boundary, auth, security, idempotency, pagination, business logic), and exports to Postman, TestRail, Allure, k6, pytest, Gherkin, and CSV. Supports internal corporate APIs with auth headers. Auto-saves export files to your working di
    10
    10 npm
    2
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    High-performance MCP server for OpenAPI specifications that parses specs, diffs versions, tracks dependencies, and generates code (TypeScript, Rust, Python).
    3 npm
    2
    MIT