name: ‘step-03b-subagent-backend’ description: ‘Subagent: Generate backend tests only (unit, integration, contract)’ subagent: true
This is an isolated subagent running in parallel with API test generation (and optionally E2E test generation for fullstack projects).
What you have from parent workflow:
Your task: Generate backend tests ONLY (unit, integration, contract - not API endpoint tests, not E2E).
From the coverage plan (Step 2 output), identify:
From config.test_framework and project manifests, determine:
pytest conventions, conftest.py fixtures, @pytest.mark decorators@Test, @BeforeEach, @Nested), Mockito for mocking*_test.go files, testing.T, table-driven tests, testify assertions[Fact], [Theory], [InlineData], Moq for mockingdescribe/context/it blocks, let/before helpers, FactoryBotFor each module/service, create test files following language-idiomatic patterns:
Python (pytest) example:
import pytest
from unittest.mock import MagicMock, patch
from myapp.services.user_service import UserService
class TestUserService:
"""[P0] Unit tests for UserService"""
def test_create_user_with_valid_data(self, user_factory):
"""Should create user when data is valid"""
user_data = user_factory.build()
result = UserService.create(user_data)
assert result.email == user_data["email"]
def test_create_user_rejects_duplicate_email(self, user_factory):
"""[P1] Should reject duplicate email"""
user_data = user_factory.build(email="existing@test.com")
with pytest.raises(DuplicateEmailError):
UserService.create(user_data)
Go (go test) example:
func TestUserService_Create(t *testing.T) {
tests := []struct {
name string
input CreateUserInput
wantErr bool
}{
{"valid user", validInput(), false},
{"duplicate email", duplicateInput(), true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
svc := NewUserService(mockRepo)
_, err := svc.Create(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("Create() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
Requirements:
For service integrations, create integration test files:
If the project uses microservices or has defined API contracts:
Identify fixtures/helpers needed for backend tests:
Do NOT create fixtures yet - just track what’s needed for aggregation step.
Write JSON to temp file: /tmp/tea-automate-backend-tests-{{timestamp}}.json
{
"subagentType": "backend",
"testsGenerated": [
{
"file": "tests/unit/test_user_service.py",
"content": "[full test file content]",
"description": "Unit tests for UserService",
"priority_coverage": {
"P0": 3,
"P1": 2,
"P2": 1,
"P3": 0
}
},
{
"file": "tests/integration/test_user_repository.py",
"content": "[full test file content]",
"description": "Integration tests for user database operations",
"priority_coverage": {
"P0": 1,
"P1": 2,
"P2": 1,
"P3": 0
}
}
],
"coverageSummary": {
"totalTests": 15,
"testLevels": ["unit", "integration", "contract"],
"fixtureNeeds": ["databaseFixture", "userFactory", "mockHttpClient"]
},
"status": "complete",
"success": true,
"subagent": "backend-tests",
"knowledge_fragments_used": ["test-levels-framework", "test-priorities-matrix", "data-factories"],
"summary": "Generated 15 backend test cases (10 unit, 4 integration, 1 contract)"
}
On Error:
{
"subagentType": "backend",
"testsGenerated": [],
"coverageSummary": {
"totalTests": 0,
"testLevels": [],
"fixtureNeeds": []
},
"status": "partial",
"success": false,
"subagent": "backend-tests",
"error": "Error message describing what went wrong",
"partial_output": {
/* any tests generated before error */
}
}
Subagent completes when:
Subagent terminates here. Parent workflow will read output and proceed to aggregation.