.agents/commands/comet/create-and-run-tests.md
Command: cursor create-and-run-tests
Create comprehensive tests for new features and run only relevant tests (new, updated, or modified) to ensure code quality and functionality. This command provides Cursor-native test creation and execution that integrates seamlessly with daily development, optimizing for large project workflows.
This workflow will:
pom.xml, Java source files, Maven structurepackage.json, React/TypeScript files, Vite configpyproject.toml, Python source files, pytest configpackage.json, TypeScript files, tsup configsrc/main/java structure in src/test/javashouldCreateUser_whenValidRequest, shouldThrowBadRequestException_whenInvalidInputapps/opik-backend/src/test/java/should render user profile, should handle form submissionapps/opik-frontend/src/ or apps/opik-frontend/e2e/src/opik structure in tests/test_create_user__happyflow, test_create_user__when_invalid_email__throws_bad_request_exceptionsdks/python/tests/tests/should create user when valid request, should throw error when invalid inputsdks/typescript/tests/# Backend - Run specific test classes or packages
mvn test -Dtest="UserServiceTest"
mvn test -Dtest="UserServiceTest#shouldCreateUser_whenValidRequest"
# Frontend - Run tests for changed v1
npm test -- UserProfile.test.tsx
npm test -- --run src/v1/UserProfile/
# Python SDK - Run specific test files or functions
pytest tests/unit/test_user_service.py
pytest tests/unit/test_user_service.py::test_create_user__happyflow
# TypeScript SDK - Run specific test files
npm test -- UserService.test.ts
PodamFactoryUtils.newPodamFactory()@Test
void shouldCreateUser_whenValidRequest() {
// Given
var request = podamFactory.manufacturePojo(UserCreateRequest.class)
.toBuilder()
.name("John Doe")
.email("[email protected]")
.build();
var expectedId = "user-123";
when(idGenerator.generate()).thenReturn(expectedId);
when(userDao.create(any(User.class))).thenReturn(expectedUser);
// When
var actualUser = userService.createUser(request);
// Then
assertThat(actualUser).isEqualTo(expectedUser);
verify(userDao).create(any(User.class));
}
test('should render user profile with data', async () => {
// Given
const mockUser = { id: '1', name: 'John Doe', email: '[email protected]' };
vi.mocked(useUser).mockReturnValue({ data: mockUser, isLoading: false });
// When
render(<UserProfile userId="1" />);
// Then
expect(screen.getByText('John Doe')).toBeInTheDocument();
expect(screen.getByText('[email protected]')).toBeInTheDocument();
});
TraceModel, SpanModel, assert_equaldef test_create_user__happyflow(fake_backend):
# Given
request = UserCreateRequest(name="John Doe", email="[email protected]")
# When
actual_user = user_service.create_user(request)
# Then
assert actual_user is not None
assert actual_user.name == request.name
test('should create user when valid request', async () => {
// Given
const mockUser = { id: '1', name: 'John Doe' };
vi.mocked(fetch).mockResolvedValueOnce({
ok: true,
json: async () => mockUser,
} as Response);
// When
const result = await client.createUser({ name: 'John Doe' });
// Then
expect(result).toEqual(mockUser);
});
# For new tests
git commit -m "Revision X: Add comprehensive tests for <feature>"
# For test fixes
git commit -m "Revision X: Fix failing test cases"
The command is successful when:
End Command