// Comprehensive testing strategies, test automation, quality assurance with JUnit, MockK, Jest. Use for testing, test, qa, quality, coverage tags. Provides test patterns, validation commands, coverage targets.
| name | Testing Implementation |
| description | Comprehensive testing strategies, test automation, quality assurance with JUnit, MockK, Jest. Use for testing, test, qa, quality, coverage tags. Provides test patterns, validation commands, coverage targets. |
| allowed-tools | Read, Write, Edit, Bash, Grep, Glob |
Domain-specific guidance for writing comprehensive tests, test automation, and quality assurance.
Load this Skill when task has tags:
testing, test, qa, quality, coverageunit-test, integration-test, e2e, jest, junit# Gradle (Kotlin/Java)
./gradlew test
./gradlew test --tests "*UserServiceTest*"
./gradlew test --tests "UserServiceTest.shouldCreateUser"
# NPM (JavaScript/TypeScript)
npm test
npm test -- --coverage
npm test -- UserService.test.ts
npm test -- -t "should create user"
# Python
pytest
pytest tests/test_user_service.py
pytest tests/test_user_service.py::test_create_user
pytest --cov=src tests/
# Gradle
./gradlew test jacocoTestReport
# Report: build/reports/jacoco/test/html/index.html
# NPM
npm test -- --coverage
# Report: coverage/lcov-report/index.html
# Python
pytest --cov=src --cov-report=html tests/
# Report: htmlcov/index.html
โ ALL tests MUST pass (0 failures) โ Coverage goals met (specified in task, typically 80%+) โ No flaky tests (run multiple times to verify) โ Test execution time acceptable (< 5min for unit tests) โ All edge cases covered
Unit Tests (70% of tests):
Integration Tests (20% of tests):
E2E Tests (10% of tests):
@Test
fun `should calculate total with tax`() {
// Arrange - Set up test data
val items = listOf(
Item(price = 10.0),
Item(price = 20.0)
)
val taxRate = 0.1
// Act - Execute the function being tested
val total = calculateTotal(items, taxRate)
// Assert - Verify the result
assertEquals(33.0, total)
}
@Test
fun `should handle empty list`() {
val result = calculateTotal(emptyList(), 0.1)
assertEquals(0.0, result)
}
@Test
fun `should handle zero tax rate`() {
val items = listOf(Item(price = 10.0))
val result = calculateTotal(items, 0.0)
assertEquals(10.0, result)
}
@Test
fun `should handle negative prices`() {
val items = listOf(Item(price = -10.0))
assertThrows<IllegalArgumentException> {
calculateTotal(items, 0.1)
}
}
@Test
fun `should throw when user not found`() {
val nonExistentId = UUID.randomUUID()
assertThrows<NotFoundException> {
userService.getUserById(nonExistentId)
}
}
@Test
fun `should return error response for invalid email`() {
val response = api.createUser(email = "invalid-email")
assertEquals(400, response.statusCode)
assertTrue(response.body.contains("Invalid email"))
}
Issue: Tests fail because code being tested has bugs
What to try:
If blocked: Report to orchestrator - implementation needs fixing by Senior Engineer
Issue: No test database, mock servers, or fixtures available
What to try:
If blocked: Report to orchestrator - test infrastructure needs provisioning
Issue: Existing tests fail randomly, making new test validation impossible
What to try:
./gradlew test --tests "NewTestClass"If blocked: Report to orchestrator - flaky tests need fixing first
Issue: Don't know what behavior to test or what's expected
What to try:
If blocked: Report to orchestrator - need clarification on expected behavior
Issue: Bug report unclear, can't write test that reproduces issue
What to try:
If blocked: Report to orchestrator - need clearer reproduction steps
โ ๏ธ BLOCKED - Requires Senior Engineer
Issue: [Specific problem - implementation bug, missing fixtures, unclear requirements]
Attempted Fixes:
- [What you tried #1]
- [What you tried #2]
- [Why attempts didn't work]
Root Cause (if known): [Your analysis]
Partial Progress: [What tests you DID complete]
Context for Senior Engineer:
- Test output: [Test failures]
- Code being tested: [File and method]
- Test code: [Your test code]
Requires: [What needs to happen]
@Test
fun `should fetch user from API`() {
// Arrange - Mock external API
val mockApi = mockk<UserApi>()
every { mockApi.getUser(any()) } returns User(id = "123", name = "John")
val service = UserService(mockApi)
// Act
val user = service.getUserById("123")
// Assert
assertEquals("John", user.name)
verify { mockApi.getUser("123") }
}
@SpringBootTest
@Transactional // Auto-rollback after each test
class UserRepositoryTest {
@Autowired
private lateinit var userRepository: UserRepository
@Test
fun `should save and retrieve user`() {
// Arrange
val user = User(email = "test@example.com", name = "Test")
// Act
val saved = userRepository.save(user)
val retrieved = userRepository.findById(saved.id)
// Assert
assertNotNull(retrieved)
assertEquals("test@example.com", retrieved?.email)
}
}
test('should fetch data asynchronously', async () => {
// Arrange
const api = new UserApi();
// Act
const user = await api.getUser('123');
// Assert
expect(user.name).toBe('John');
});
@Test
fun `should handle network error gracefully`() {
// Arrange - Mock to throw exception
val mockApi = mockk<UserApi>()
every { mockApi.getUser(any()) } throws NetworkException("Connection failed")
val service = UserService(mockApi)
// Act & Assert
assertThrows<ServiceException> {
service.getUserById("123")
}
}
Good Coverage:
Lower Coverage OK:
Focus on:
shouldCreateUserWhenValidData)โ Don't skip edge case testing โ Don't write tests that depend on order โ Don't test implementation details โ Don't create flaky tests (timing-dependent) โ Don't mock everything (use real infrastructure where appropriate) โ Don't skip test cleanup (database, files) โ Don't mark task complete with failing tests
When reading task sections, prioritize:
requirements - What needs testingtesting-strategy - Test approachacceptance-criteria - Success conditionsimplementation - Code to testFor deeper patterns and examples, see: