An IntelliJ IDEA plugin that automatically generates comprehensive JUnit 5 unit tests for Java methods using the Groq AI API (free, no credit card required).
Install from JetBrains Marketplace
- You place your cursor inside any Java method
- Right-click → Generate Unit Test with AI
- The plugin extracts the method context and sends it to Groq AI
- A complete test file is generated and written to your
src/testdirectory
Generated tests include:
- Happy path tests
- Edge case tests (null inputs, empty collections, boundary values)
- Error case tests
- Mockito mocks for dependencies
@DisplayNameannotations with descriptive names- Arrange-Act-Assert pattern
| Layer | Technology |
|---|---|
| Language | Java |
| Build System | Gradle (Kotlin DSL) |
| Target IDE | IntelliJ IDEA 2024.1+ |
| AI Backend | Groq API (llama-3.3-70b-versatile) |
| HTTP Client | OkHttp 4.12.0 |
| JSON Parsing | Gson 2.11.0 |
| Testing | JUnit 4 + Mockito 5 + OkHttp MockWebServer |
- IntelliJ IDEA 2024.1 or newer (Community or Ultimate)
- Java 17+
- A free Groq API key (get one at console.groq.com)
- In IntelliJ: Settings → Plugins → Marketplace
- Search for "AI Test Case Generator"
- Click Install → Restart IDE
Or install directly: AI Test Case Generator on JetBrains Marketplace
-
Clone the repository:
git clone https://github.com/codewithrohan/ai-test-generator.git cd ai-test-generator -
Build the plugin:
./gradlew buildPlugin # Windows: .\gradlew.bat buildPlugin
-
Install in IntelliJ:
- Settings → Plugins → ⚙ → Install Plugin from Disk
- Select
build/distributions/ai-test-generator-0.1.0.zip - Restart IDE
- Get a free API key at console.groq.com → API Keys → Create
- In IntelliJ: Settings → Tools → AI Test Generator
- Paste your Groq API key
- Select model (default:
llama-3.3-70b-versatile) - Click Apply
- Open any Java file with a method
- Click your cursor inside the method body
- Right-click → Generate Unit Test with AI
- Wait a few seconds
- Test file appears in
src/test/java/...
src/
├── main/java/com/aitestgen/
│ ├── action/ # Right-click menu action
│ ├── client/ # Groq API HTTP client
│ ├── extractor/ # Extracts method context from PSI tree
│ ├── generator/ # Writes generated test files to disk
│ ├── model/ # Data models (MethodContext, GeneratedTestResult)
│ ├── prompt/ # Builds structured prompts for the AI
│ └── settings/ # Plugin settings UI and state
└── test/java/com/aitestgen/
└── ... # Unit tests for each component
Groq offers a free tier with no credit card required, making the plugin accessible to any developer without billing setup. It also provides fast inference times (~1-2s), which keeps the UX responsive.
The Anthropic/OpenAI Java SDKs pull in heavy transitive dependency trees. A plugin should be lightweight — OkHttp + Gson are just two small JARs with minimal transitive deps. The API surface we need is a single POST endpoint, so an SDK adds complexity without value.
IntelliJ's PSI (Program Structure Interface) gives us structured access to the method's class, package, imports, fields, annotations, and superclass. This lets us build a rich, structured prompt that produces significantly better tests than sending raw source text. The AI knows exactly what dependencies to mock and what patterns to follow.
A common failure mode in AI-generated tests is incorrect constructor arguments or method calls on domain types. By extracting constructor and public method signatures from types used in the method under test, the AI can generate compilable code on the first try.
IntelliJ requires careful thread management:
- PSI reads run inside
ReadAction.compute()to hold the read lock - HTTP calls run on a
Task.Backgroundablethread to avoid freezing the UI - File writes dispatch to EDT via
invokeLaterand run insideWriteCommandAction - Action updates use
ActionUpdateThread.BGTfor background thread evaluation with automatic read access
API keys are stored in the OS keychain via IntelliJ's PasswordSafe API (Windows Credential Manager / macOS Keychain / KDE Wallet). Keys are never written to plain text XML or committed to version control.
This plugin was built with the assistance of Claude Code (Anthropic's CLI tool). Here's how AI was involved at each stage:
- Scaffolding — Claude Code generated the initial project skeleton (Gradle config, plugin.xml, model classes) based on a detailed implementation plan
- Code review — An AI-powered code reviewer analyzed all source files and caught 10 critical/important issues including threading violations (VFS operations outside WriteAction, PSI access without ReadAction) and incorrect IntelliJ API usage — bugs that would only surface as runtime crashes
- Test generation — Claude Code wrote the initial test suite; MockWebServer-based HTTP tests and BasePlatformTestCase PSI tests were AI-assisted
- Iteration — AI identified that
project.getBaseDir()was deprecated, thatJavaCodeStyleManagerhad a different import path than expected, and thatinstrumentationTools()was no longer needed
Human decisions throughout: Architecture choices, API provider selection (Groq), what PSI context to extract, prompt engineering strategy, and the decision to add relatedTypeSignatures for better test accuracy.
This plugin has been submitted to the JetBrains Marketplace and is currently under moderation review. Once approved, it will be installable directly from IntelliJ's plugin marketplace.
MIT