Generate Tests From Business Logic logo

Generate Tests From Business Logic

Community
meirm
generate-tests-from-business-logic

Generates scenario tests, rule tests, edge case tests, state transition tests, and billing tests from trusted business logic. Use when creating test suites from BL, ensuring BL coverage, or turning requirements into verifiable tests.

Overview

Publishermeirm
Repositoryreverse-engineering-skill
Skill namegenerate-tests-from-business-logic
Stars
46
Forks
7
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by meirm on GitHub. Read the source before you install it.

Installation

Install the Generate Tests From Business Logic AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/meirm/reverse-engineering-skill/tree/main/skills/generate-tests-from-business-logic
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/meirm/reverse-engineering-skill.git /tmp/reverse-engineering-skill
mkdir -p .claude/skills
cp -r /tmp/reverse-engineering-skill/skills/generate-tests-from-business-logic .claude/skills/generate-tests-from-business-logic
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Generate Tests From Business Logic in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Generate Tests From Business Logic on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Generate Tests From Business Logic is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Generating Tests from Business Logic

Project-agnostic. Use BDD/project_config.yaml for terminology and code paths when present; write tests in the project's test framework and structure (see tailor-bdd-skills-for-project).

Purpose

Transform trusted business logic into a comprehensive test suite that continuously verifies implementation against business behavior. This is the BL enforcement skill.

Prerequisites

  • Refined business logic document (use refine-business-logic-for-implementation first)
  • Understanding of the project's testing framework (pytest, behave, etc.)
  • Knowledge of the project structure

Instructions

Step 1: Parse the Business Logic

Read the refined BL document and identify:

bash
cat path/to/refined_bl_document.md

Extract:

  • All business rules (validation, billing, workflows)
  • State machine definitions (states and transitions)
  • Decision tables
  • Invariants
  • Error handling rules
  • Billing/credit rules

Step 2: Classify Test Types

Organize tests into these categories:

A. Rule Tests - Verify individual business rules B. Scenario Tests - Verify end-to-end workflows C. State Transition Tests - Verify state machine correctness D. Edge Case Tests - Verify boundary conditions E. Billing Tests - Verify credit operations F. Regression Tests - Verify past bugs don't recur

Step 3: Generate Rule Coverage Tests

For each decision rule, generate three tests:

markdown
For every decision rule:
  - One happy path test (rule should succeed)
  - One negative path test (rule should fail)
  - One edge/boundary test (boundary condition)

Example:

markdown
BL Rule: "Request is rejected if identifier is invalid"

Generated Tests:
1. test_request_accepted_with_valid_identifier() - Happy path
2. test_request_rejected_with_invalid_identifier_format() - Negative path
3. test_request_rejected_with_empty_identifier() - Edge case (empty)
4. test_request_rejected_with_too_short_identifier() - Edge case (boundary)

Step 4: Generate State Transition Tests

For each state transition in the state machine:

markdown
For every valid transition:
  - Test that transition is allowed

For every forbidden transition:
  - Test that transition is blocked
  - Test that appropriate error is raised

For every terminal state:
  - Test that no further transitions are possible

Example:

markdown
BL States: PENDING → VALIDATED → SUBMITTED → PROCESSING → COMPLETED

Generated Tests:
1. test_pending_to_validated_on_valid_input() - Valid transition
2. test_cannot_transition_from_completed_to_processing() - Forbidden transition
3. test_query_in_completed_state_is_terminal() - Terminal state check

Step 5: Generate Billing/Credit Tests

For every charge/refund rule:

markdown
For every charge rule:
  - Test that charge occurs at the right time
  - Test that charge amount is correct
  - Test that charge does NOT occur when conditions not met

For every refund rule:
  - Test refund conditions
  - Test refund amount matches original charge

For partial success:
  - Test billing semantics
  - Test duplicate request semantics

Example:

markdown
BL Rule: "Balance deducted before [external] submission"

Generated Tests:
1. test_balance_deducted_on_submission() - Verify deduction
2. test_balance_not_deducted_if_validation_fails() - Verify no deduction
3. test_balance_not_deducted_if_insufficient() - Verify no deduction
4. test_deduction_amount_matches_cost() - Verify amount

Step 6: Generate Scenario Tests

For each workflow, generate end-to-end scenarios:

markdown
Scenario Format (Given/When/Then):
  Given: Initial state and conditions
  When: Action is taken
  Then: Expected outcome

Example:

markdown
BL Workflow: Query submission and processing

Generated Scenario:
Scenario: Successful query processing
  Given a tenant with sufficient credits
  And a valid MSISDN
  When the user submits a geolocation query
  Then the query is created with status PENDING
  And credits are deducted
  And the query is submitted to the provider
  And the query status becomes SUBMITTED

Step 7: Generate Edge Case Tests

Test boundary conditions and unusual inputs:

markdown
Common edge cases to test:
  - Empty/null values
  - Minimum and maximum values
  - Concurrent operations
  - Race conditions
  - Resource exhaustion
  - Network failures
  - Timeout scenarios

Example:

markdown
Generated Edge Case Tests:
1. test_query_with_maximum_length_msisdn() - Boundary test
2. test_concurrent_query_submission_same_msisdn() - Race condition
3. test_query_when_provider_timeout() - Timeout scenario
4. test_query_submission_with_zero_credits() - Boundary condition

Step 8: Output Test Files

Generate test files in the appropriate format:

For pytest (Python):

python
# tests/test_<domain>_bl.py

import pytest
# Import project models (e.g. Request, Account, Ledger)

class TestRequestSubmissionBL:
    """Tests for [Request/Operation] Submission Business Logic"""

    def test_request_accepted_with_valid_input(self):
        # Given
        account = create_account(balance=100)  # project-specific factory
        valid_input = "..."

        # When
        response = api_client.post('/api/requests/', {...})

        # Then
        assert response.status_code == 201
        assert Request.objects.filter(...).exists()

    def test_request_rejected_with_invalid_input(self):
        # ... implementation

For behave (BDD):

gherkin
# features/<domain>_bl.feature

Feature: [Operation] Submission Business Logic

  Scenario: Valid request is accepted
    Given an account with sufficient balance
    And valid input
    When the user submits the [operation]
    Then the request should be created
    And balance should be deducted (if applicable)

  Scenario: Invalid input is rejected
    Given an account with sufficient balance
    And invalid input format
    When the user submits the [operation]
    Then the request should be rejected
    And no balance should be deducted

Step 9: Create Test Coverage Matrix

Document which BL rules are covered by which tests:

markdown
## Test Coverage Matrix

| BL Rule | Test Type | Test Name | Coverage |
|---------|-----------|-----------|----------|
| Balance deducted on submission | Billing | test_balance_deducted_on_submission | ✅ |
| Invalid input rejected | Rule | test_request_rejected_with_invalid_input | ✅ |
| PENDING → VALIDATED on valid input | State Transition | test_pending_to_validated_on_valid_input | ✅ |

Step 10: Save Generated Tests

bash
# Create test directory structure
mkdir -p tests/bl
mkdir -p features/bl

# Save generated tests
cat > tests/test_<domain>_bl.py
cat > features/<domain>_bl.feature

Test Generation Templates

Rule Test Template

python
def test_{rule_name}_{expected_outcome}():
    """
    BL Rule: {rule_description}

    Expected: {expected_behavior}
    """
    # Given
    {setup_conditions}

    # When
    {action_taken}

    # Then
    {expected_result}

State Transition Test Template

python
def test_{from_state}_to_{to_state}_{condition}():
    """
    BL Transition: {from_state} → {to_state}

    Condition: {trigger_condition}
    """
    # Given
    entity = create_entity_with_state("{from_state}")

    # When
    entity.{trigger_action}()

    # Then
    assert entity.state == "{to_state}"

Billing Test Template

python
def test_{billing_event}_credits_{expected_action}():
    """
    BL Billing Rule: {billing_rule}

    Expected: {credits_action} (deducted/not_deducted/refunded)
    """
    # Given
    initial_credits = {amount}
    tenant = create_tenant_with_credits(initial_credits)

    # When
    {billing_event_action}

    # Then
    final_credits = tenant.credits
    assert final_credits == {expected_credits}

Test Coverage Checklist

For each BL rule, verify coverage of:

  • Happy path (successful execution)
  • Negative path (error conditions)
  • Edge cases (boundaries, unusual inputs)
  • State transitions (valid and invalid)
  • Billing operations (charges and refunds)
  • Concurrent operations (race conditions)
  • Idempotency (duplicate operations)
  • Timeout scenarios
  • Error recovery (fallback, retry)

Examples

Example 1: Generating Tests for Credit Logic

User request:

Generate tests from the credit deduction business logic

You would:

  1. Read the refined BL for credit rules
  2. Extract rules:
    • "Credits deducted before provider submission"
    • "Query rejected if insufficient credits"
    • "No refund for failed queries"
  3. Generate tests:
    python
    def test_credits_deducted_on_query_submission():
        """Verify credits are deducted when query is submitted"""
        pass
    
    def test_query_rejected_if_insufficient_credits():
        """Verify query is rejected when tenant lacks credits"""
        pass
    
    def test_no_refund_for_failed_queries():
        """Verify no credit refund when provider returns error"""
        pass
    
    def test_credits_deducted_prevents_negative_balance():
        """Verify credits cannot go negative due to race condition"""
        pass
    
    def test_concurrent_queries_with_exact_balance():
        """Verify concurrent queries respect balance limits"""
        pass
  4. Create test file: tests/test_credit_bl.py
  5. Generate coverage matrix

Example 2: Generating Tests for Provider Fallback

User request:

Create tests for the provider fallback logic

You would:

  1. Parse fallback BL rules
  2. Generate state transition tests:
    python
    def test_fallback_to_secondary_on_primary_timeout():
        """Verify fallback occurs when primary times out"""
        pass
    
    def test_no_fallback_on_invalid_target_error():
        """Verify no fallback for INVALID_TARGET from primary"""
        pass
    
    def test_fallback_occurs_once_per_query():
        """Verify fallback happens only once, not multiple times"""
        pass
    
    def test_query_stalled_after_all_providers_fail():
        """Verify STALLED status after all providers exhausted"""
        pass
  3. Generate edge case tests:
    python
    def test_both_primary_and_secondary_timeout():
        """Verify STALLED when both providers timeout"""
        pass
    
    def test_primary_returns_500_error():
        """Verify fallback for 500 error"""
        pass
    
    def test_fallback_with_different_cost_provider():
        """Verify correct cost used for fallback provider"""
        pass

Output Artifacts

The skill generates:

  1. Test files in appropriate format (pytest, behave, etc.)
  2. Test coverage matrix mapping BL rules to tests
  3. Coverage statistics showing percentage of BL rules tested
  4. Test documentation explaining test organization and naming conventions

Frequently asked questions

What does the Generate Tests From Business Logic AI skill do?

Generates scenario tests, rule tests, edge case tests, state transition tests, and billing tests from trusted business logic. Use when creating test suites from BL, ensuring BL coverage, or turning requirements into verifiable tests.

Why use Generate Tests From Business Logic on TypingMind?

Because you install it once and use it with any model. Generate Tests From Business Logic is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Generate Tests From Business Logic in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/meirm/reverse-engineering-skill/tree/main/skills/generate-tests-from-business-logic. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Generate Tests From Business Logic?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Generate Tests From Business Logic?

As many as you like. As long as a model supports skills, you can use Generate Tests From Business Logic with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Generate Tests From Business Logic AI skill free?

Yes. It is published on GitHub by meirm under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇