mcpbeat Sign in

Mocking Test Generator Agent Skill

Generate unit tests with proper mocking for Python (unittest.mock/pytest) or Java (Mockito/JUnit) code. Use when users request test generation, unit tests with mocks, or testing code that has external dependencies like database calls, API requests, file I/O, or network operations. Automatically identifies dependencies to mock and creates executable, maintainable test code.

4k tokens
context cost
the whole folder, loaded on every use
3
files
instructions only
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill mocking-test-generator

The instruction itself

11 sections, as written by the author

Mocking Test Generator

Generate unit tests with proper mocking of external dependencies for Python and Java code.

Workflow

  • Analyze the code - Identify external dependencies, side effects, and testable units
  • Select framework - Determine Python (unittest.mock/pytest) or Java (Mockito/JUnit)
  • Generate mocks - Create mock objects for external dependencies
  • Write tests - Generate executable test code with assertions
  • Add documentation - Include clear comments explaining mocks and test logic

Step 1: Analyze the Code

Read the target code to identify:

  • External dependencies: API clients, database connections, third-party libraries
  • I/O operations: File reads/writes, network requests, system calls
  • Side effects: Email sending, logging, state modifications
  • Testable units: Functions, methods, or classes to test in isolation

Ask clarifying questions if:

  • Multiple functions/classes exist (which to test?)
  • Testing scope is unclear (unit vs integration?)
  • Mock behavior needs specification (return values, exceptions?)

Step 2: Select Framework

Python: Use unittest.mock with pytest or unittest

  • Prefer @patch decorator for external calls
  • Use Mock() objects for complex dependencies
  • Apply pytest.fixture for reusable mocks

Java: Use Mockito with JUnit 5

  • Use @Mock annotation for dependencies
  • Apply @ExtendWith(MockitoExtension.class) to test class
  • Use when().thenReturn() for stubbing

Step 3: Generate Mocks

Identify what to mock:

Always mock:

  • External API calls (HTTP requests, REST clients)
  • Database connections and queries
  • File system operations
  • Network I/O
  • Time/date functions
  • Random number generators
  • Environment variables

Never mock (unless explicitly requested):

  • Internal business logic
  • Pure functions
  • Data structures
  • Simple utilities

For common patterns, reference:

  • Python: See references/python_patterns.md
  • Java: See references/java_patterns.md

Step 4: Write Tests

Generate test code that:

  • Imports - Include necessary testing and mocking libraries
  • Setup - Initialize mocks and test fixtures
  • Execution - Call the function/method under test
  • Assertions - Verify expected behavior and outputs
  • Verification - Confirm mocks were called correctly

Test structure:

# Python example
from unittest.mock import patch, Mock
import pytest

@patch('module.external_dependency')
def test_function_name(mock_dependency):
    # Arrange: Setup mock behavior
    mock_dependency.return_value = expected_value

    # Act: Execute function under test
    result = function_under_test(input_data)

    # Assert: Verify results
    assert result == expected_output
    mock_dependency.assert_called_once_with(expected_args)
// Java example
@ExtendWith(MockitoExtension.class)
class ServiceTest {
    @Mock
    private ExternalDependency dependency;

    @Test
    void testMethodName() {
        // Arrange: Setup mock behavior
        when(dependency.method()).thenReturn(expectedValue);

        // Act: Execute method under test
        Service service = new Service(dependency);
        String result = service.methodUnderTest();

        // Assert: Verify results
        assertEquals(expectedOutput, result);
        verify(dependency).method();
    }
}

Include:

  • Multiple test cases for different scenarios (happy path, edge cases, errors)
  • Descriptive test names that explain what is being tested
  • Setup/teardown if needed for test isolation

Step 5: Add Documentation

Include comments that explain:

  • What external dependency is being mocked and why
  • What behavior the mock simulates
  • What the test verifies

Keep comments concise and focused on non-obvious aspects.

Output Format

Provide:

  • Complete test file - Fully executable with all imports
  • Test class/module - Properly structured for the framework
  • Multiple test methods - Cover main scenarios
  • Clear naming - Descriptive test and variable names

Do not:

  • Modify the original code under test
  • Mock internal logic unless explicitly requested
  • Generate incomplete or pseudo-code tests

Example Usage

User request: "Generate unit tests for this Python function that calls an external API"

Response:

  • Read the function code
  • Identify the API call to mock
  • Generate pytest test file with @patch decorator
  • Include tests for success case, error handling, and edge cases
  • Add comments explaining the mock setup

Framework-Specific Notes

Python (pytest):

  • Use @pytest.fixture for reusable mock setups
  • Apply @patch as decorator or context manager
  • Use mock_open for file operations
  • Apply @patch.dict for environment variables

Python (unittest):

  • Use unittest.TestCase base class
  • Apply @patch decorator or patch() context manager
  • Use setUp() and tearDown() methods
  • Call self.assert* methods

Java (Mockito + JUnit 5):

  • Use @ExtendWith(MockitoExtension.class) on test class
  • Apply @Mock for dependencies
  • Use @BeforeEach for setup, @AfterEach for teardown
  • Apply ArgumentCaptor to verify complex arguments
  • Use MockedStatic for static method mocking (Mockito 3.4+)

Common Patterns

Reference files contain detailed examples for:

Python (references/python_patterns.md):

  • External API calls
  • Database operations
  • File system operations
  • Environment variables
  • Time-dependent code
  • Exception handling

Java (references/java_patterns.md):

  • External API calls
  • Database operations
  • File system operations
  • Void methods
  • Exception handling
  • Argument captors
  • Static method mocking
  • Constructor mocking

Other skills for the same job

different authors, same section of the catalogue
Webapp Testing
by anthropics
vendor ×12

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

6k tokens scripts
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
Test Driven Development
by w95
×7

Use when implementing any feature or bugfix, before writing implementation code

2k tokens
Systematic Debugging
by ratacat
×7

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

10k tokens scripts
Verification Before Completion
by ZhanlinCui
×6

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

1k tokens
Backtest Expert
by BaggaT236
×3

Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.

15k tokens scripts
Adaptyv
by christophacham
×3

Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.

16k tokens
Aeon
by christophacham
×3

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

19k tokens

How to use it

Copy the folder

Take arabelatso/mocking-test-generator from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.