# test/models/user_test.rb
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "valid user with all attributes" do
user = User.new(email: "test@example.com", name: "Test User")
assert user.valid?
end
test "invalid without email" do
user = User.new(name: "Test User")
assert_not user.valid?
assert_includes user.errors[:email], "can't be blank"
end
test "invalid with duplicate email" do
existing = users(:one)
user = User.new(email: existing.email, name: "New User")
assert_not user.valid?
end
end
Best Practices
Run existing tests before generating new ones
Review generated tests for accuracy
Maintain test isolation
Use descriptive test names
Raw Content
# Test Generator Agent
An autonomous agent that analyzes code and generates comprehensive test suites.
## Capabilities
- **Unit Test Generation**: Create tests for individual functions/methods
- **Integration Tests**: Test component interactions
- **Edge Case Discovery**: Identify and test boundary conditions
- **Mock Generation**: Create appropriate mocks and stubs
- **Coverage Analysis**: Identify untested code paths
## Supported Frameworks
- **JavaScript/TypeScript**: Jest, Vitest, Mocha
- **Ruby**: Minitest, RSpec
- **Python**: pytest, unittest
- **Go**: testing package
- **Rust**: built-in test framework
## Usage
```markdown
Generate tests for the UserAuthentication class.
Include:
- Happy path tests
- Error handling tests
- Edge cases (empty input, special characters)
- Mock external dependencies
```
## Configuration
```json
{
"name": "test-generator",
"framework": "auto-detect",
"coverage_target": 80,
"include_edge_cases": true,
"mock_external": true,
"output_format": "single_file"
}
```
## Example Output
```ruby
# test/models/user_test.rb
require "test_helper"
class UserTest < ActiveSupport::TestCase
test "valid user with all attributes" do
user = User.new(email: "test@example.com", name: "Test User")
assert user.valid?
end
test "invalid without email" do
user = User.new(name: "Test User")
assert_not user.valid?
assert_includes user.errors[:email], "can't be blank"
end
test "invalid with duplicate email" do
existing = users(:one)
user = User.new(email: existing.email, name: "New User")
assert_not user.valid?
end
end
```
## Best Practices
1. Run existing tests before generating new ones
2. Review generated tests for accuracy
3. Maintain test isolation
4. Use descriptive test names