// Create comprehensive test suites by discovering and adapting to any testing framework, following project test patterns and ensuring robust coverage. Use when writing tests, improving coverage, validating functionality. Triggers: 'test', 'coverage', 'unit test', 'integration test', 'E2E', 'spec', '테스트', '커버리지', '단위 테스트', '통합 테스트', '테스트 작성', working with *.test.*, *.spec.*, test/, __tests__/.
| name | test-development |
| description | Create comprehensive test suites by discovering and adapting to any testing framework, following project test patterns and ensuring robust coverage. Use when writing tests, improving coverage, validating functionality. Triggers: 'test', 'coverage', 'unit test', 'integration test', 'E2E', 'spec', '테스트', '커버리지', '단위 테스트', '통합 테스트', '테스트 작성', working with *.test.*, *.spec.*, test/, __tests__/. |
This skill enables creation of comprehensive, project-appropriate tests by learning from existing test patterns and conventions.
Leverages: [codebase-analysis] skill for discovering testing frameworks and patterns.
Using [codebase-analysis]:
Study existing tests:
Create tests matching patterns:
// Detected: Jest framework (from jest.config.js, *.test.ts)
// Match existing pattern:
describe('ProductService', () => {
let service: ProductService;
let mockRepository: jest.Mocked<ProductRepository>;
beforeEach(() => {
mockRepository = {
findById: jest.fn(),
save: jest.fn(),
} as any;
service = new ProductService(mockRepository);
});
it('should return product when found', async () => {
// Arrange
const productId = 1;
const expectedProduct = { id: productId, name: 'Test' };
mockRepository.findById.mockResolvedValue(expectedProduct);
// Act
const result = await service.getProduct(productId);
// Assert
expect(result).toEqual(expectedProduct);
expect(mockRepository.findById).toHaveBeenCalledWith(productId);
});
});
# Detected: pytest framework (from pytest.ini, conftest.py)
# Match existing pattern:
import pytest
from services.product_service import ProductService
class TestProductService:
@pytest.fixture
def service(self, mock_repository):
return ProductService(mock_repository)
@pytest.fixture
def mock_repository(self, mocker):
return mocker.Mock()
def test_get_product_returns_product_when_found(self, service, mock_repository):
# Arrange
product_id = 1
expected_product = Product(id=product_id, name="Test")
mock_repository.find_by_id.return_value = expected_product
# Act
result = service.get_product(product_id)
# Assert
assert result == expected_product
mock_repository.find_by_id.assert_called_once_with(product_id)
// Detected: Standard go test framework (from *_test.go files)
// Match existing pattern:
package product
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type MockRepository struct {
mock.Mock
}
func (m *MockRepository) FindByID(id int) (*Product, error) {
args := m.Called(id)
return args.Get(0).(*Product), args.Error(1)
}
func TestProductService_GetProduct_ReturnsProductWhenFound(t *testing.T) {
// Arrange
mockRepo := new(MockRepository)
service := NewProductService(mockRepo)
productID := 1
expectedProduct := &Product{ID: productID, Name: "Test"}
mockRepo.On("FindByID", productID).Return(expectedProduct, nil)
// Act
result, err := service.GetProduct(productID)
// Assert
assert.NoError(t, err)
assert.Equal(t, expectedProduct, result)
mockRepo.AssertExpectations(t)
}
// Detected: JUnit 5 + Mockito (from @Test, @ExtendWith annotations)
// Match existing pattern:
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.mockito.Mock;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class ProductServiceTest {
@Mock
private ProductRepository productRepository;
@InjectMocks
private ProductService productService;
@Test
@DisplayName("Should return product when found")
void getProduct_WhenProductExists_ReturnsProduct() {
// Arrange
Long productId = 1L;
Product expectedProduct = Product.builder()
.id(productId)
.name("Test Product")
.build();
when(productRepository.findById(productId))
.thenReturn(Optional.of(expectedProduct));
// Act
Product result = productService.getProduct(productId);
// Assert
assertThat(result).isEqualTo(expectedProduct);
verify(productRepository).findById(productId);
}
}
# Learn from existing tests:
# Pattern found: test_methodName_condition_expectedResult
# ✅ Match the pattern:
def test_createProduct_withValidData_returnsProduct():
pass
def test_createProduct_withDuplicateName_raisesValidationError():
pass
def test_createProduct_withNegativePrice_raisesValidationError():
pass
// Learn from existing tests:
// Pattern found: Describe blocks for class, nested for methods
// ✅ Match the structure:
describe('OrderService', () => {
describe('createOrder', () => {
it('should create order with valid data', () => {});
it('should throw error with invalid customer', () => {});
it('should throw error with empty items', () => {});
});
describe('cancelOrder', () => {
it('should cancel order when pending', () => {});
it('should throw error when already shipped', () => {});
});
});
// Learn from existing tests:
// Pattern found: expect() with matcher methods
// ✅ Match assertion style:
expect(result).toBe(expected);
expect(array).toHaveLength(3);
expect(object).toEqual({ id: 1, name: 'Test' });
expect(fn).toHaveBeenCalledWith(arg1, arg2);
// ❌ Don't use different style:
assert.equal(result, expected); // Wrong - project uses expect()
# Learn from existing tests:
# Pattern found: Fixtures in conftest.py
# ✅ Follow existing fixture pattern:
# In conftest.py
@pytest.fixture
def valid_product_data():
return {
"name": "Test Product",
"price": 99.99,
"category": "Electronics"
}
# In test file
def test_create_product_success(valid_product_data):
product = create_product(valid_product_data)
assert product.name == valid_product_data["name"]
// Focus on single unit isolation
// Test all paths: happy path + error cases + edge cases
@Test
void calculateDiscount_RegularCustomer_Returns10Percent() {
// Test happy path
}
@Test
void calculateDiscount_NullCustomer_ThrowsException() {
// Test error case
}
@Test
void calculateDiscount_ZeroAmount_ReturnsZero() {
// Test edge case
}
// Test component interactions
// Use project's integration test patterns
describe('OrderController Integration', () => {
let app: INestApplication;
let orderRepository: Repository<Order>;
beforeAll(async () => {
// Setup test database
const module = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = module.createNestApplication();
await app.init();
});
it('should create order end-to-end', async () => {
const response = await request(app.getHttpServer())
.post('/orders')
.send({ customerId: 1, items: [...] })
.expect(201);
expect(response.body).toHaveProperty('id');
});
});
# Detected: Selenium/Playwright for E2E
# Match existing E2E patterns
def test_user_can_complete_purchase_flow(browser):
# Navigate to product page
browser.goto("/products/1")
# Add to cart
browser.click("#add-to-cart")
# Proceed to checkout
browser.click("#checkout")
# Fill shipping info
browser.fill("#shipping-address", "123 Main St")
# Complete purchase
browser.click("#complete-order")
# Verify success
assert browser.is_visible("#order-confirmation")
func TestOrderService_ProcessOrder(t *testing.T) {
// Arrange
order := &Order{
ID: 1,
CustomerID: 100,
Items: []Item{{ProductID: 1, Quantity: 2}},
}
mockRepo := new(MockRepository)
service := NewOrderService(mockRepo)
// Act
result, err := service.ProcessOrder(order)
// Assert
assert.NoError(t, err)
assert.Equal(t, OrderStatus.Processing, result.Status)
}
# ✅ Each test is independent
class TestUserService:
def test_create_user(self):
service = UserService() # Fresh instance
user = service.create_user({"email": "test@example.com"})
assert user.email == "test@example.com"
def test_delete_user(self):
service = UserService() # Fresh instance
# Test doesn't depend on test_create_user
pass
// ✅ Descriptive assertions that help debug failures
it('should calculate correct total with tax', () => {
const result = calculator.calculateTotal(100);
// Good: Clear what's being tested
expect(result.subtotal).toBe(100);
expect(result.tax).toBe(10);
expect(result.total).toBe(110);
// ❌ Bad: Unclear which part failed
// expect(result).toEqual({ subtotal: 100, tax: 10, total: 110 });
});
# Detect from package.json, Makefile, justfile, etc.
# Found in package.json:
"scripts": {
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
}
# Ensure new tests work with existing commands
npm test # Must pass
npm run test:coverage # Must maintain coverage
# Learn from existing .github/workflows/test.yml
# Ensure new tests integrate with CI pipeline
# Existing CI runs:
# - npm test
# - npm run lint
# - npm run build
# New tests must pass all these checks
Before finalizing tests:
❌ Testing Implementation Details:
// Wrong - testing internal state
expect(service.internalCache.size).toBe(3);
// Right - testing behavior
expect(service.getUsers()).toHaveLength(3);
❌ Fragile Tests:
# Wrong - breaks with minor changes
assert user.created_at == datetime(2024, 1, 1, 12, 30, 45)
# Right - tests what matters
assert user.created_at is not None
assert user.created_at <= datetime.now()
❌ Dependent Tests:
// Wrong - tests depend on order
@Test
void test1_createUser() { ... }
@Test
void test2_updateUser() { // Depends on test1
// Breaks if test1 fails or runs separately
}
Remember: Great tests are readable, maintainable, and follow project patterns. Use [codebase-analysis] to discover testing conventions, then create tests that feel native to the project's testing culture.