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.
Install with Tessl CLI
npx tessl i github:ArabelaTso/Skills-4-SE --skill mocking-test-generator87
Does it follow best practices?
If you maintain this skill, you can automatically optimize it using the tessl CLI to improve its score:
npx tessl skill review --optimize ./path/to/skillValidation for skill structure
Generate unit tests with proper mocking of external dependencies for Python and Java code.
Read the target code to identify:
Ask clarifying questions if:
Python: Use unittest.mock with pytest or unittest
@patch decorator for external callsMock() objects for complex dependenciespytest.fixture for reusable mocksJava: Use Mockito with JUnit 5
@Mock annotation for dependencies@ExtendWith(MockitoExtension.class) to test classwhen().thenReturn() for stubbingIdentify what to mock:
Always mock:
Never mock (unless explicitly requested):
For common patterns, reference:
Generate test code that:
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:
Include comments that explain:
Keep comments concise and focused on non-obvious aspects.
Provide:
Do not:
User request: "Generate unit tests for this Python function that calls an external API"
Response:
@patch decoratorPython (pytest):
@pytest.fixture for reusable mock setups@patch as decorator or context managermock_open for file operations@patch.dict for environment variablesPython (unittest):
unittest.TestCase base class@patch decorator or patch() context managersetUp() and tearDown() methodsself.assert* methodsJava (Mockito + JUnit 5):
@ExtendWith(MockitoExtension.class) on test class@Mock for dependencies@BeforeEach for setup, @AfterEach for teardownArgumentCaptor to verify complex argumentsMockedStatic for static method mocking (Mockito 3.4+)Reference files contain detailed examples for:
Python (references/python_patterns.md):
Java (references/java_patterns.md):
c1fb172
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.