AgentSkillsCN

Test Generation

测试生成

SKILL.md

Test Generation

Create thorough, maintainable test suites covering happy paths, edge cases, and error handling.

Test Design

PrincipleApplication
Clear namesshould return X when Y
AAA patternArrange → Act → Assert
One behaviorEach test verifies one thing
IsolationNo shared state between tests
Specific assertstoEqual([1,2,3]) not toBeTruthy()

Coverage Checklist

  • Happy path: Normal operation
  • Edge cases: null, empty, 0, -1, MAX_INT, special chars
  • Errors: Invalid inputs, missing params, exceptions
  • Integration: External deps mocked

Framework Quick Reference

FrameworkStructureAssertMock
Jestdescribe/itexpect().toBe/toEqualjest.mock()
pytesttest_name()assert x == ymocker.patch()
JUnit@TestassertEquals()@Mock + Mockito
Mochadescribe/itChai expect().toSinon
RSpecdescribe/itexpect().to eqallow().to receive
GoTestName(t)t.Error()Manual/testify

Mocking Strategy

Mock: API calls, DB, file system, time, external services

Don't mock: Simple data, pure functions, code under test

Example Structure

javascript
describe('UserService', () => {
  describe('createUser', () => {
    it('should create user with valid data', () => {
      // Arrange
      const data = { name: 'John', email: 'john@test.com' }
      // Act
      const user = createUser(data)
      // Assert
      expect(user.name).toBe('John')
    })

    it('should throw when email invalid', () => {
      expect(() => createUser({ email: 'bad' })).toThrow(ValidationError)
    })
  })
})