Java Mock Data Generator
A VS Code extension that generates realistic mock data and Java test fixtures from JSON schemas. Perfect for testing Java applications with various data scenarios.
Features
- Generate Mock JSON Data: Create realistic mock JSON data from a schema
- Java Test Fixtures: Generate Java code with mock data for unit tests
- Smart Field Detection: Automatically detects field types (email, phone, name, URL, etc.) and generates appropriate data
- Configurable: Choose how many mock objects to generate
- Webview UI: Interactive interface in VS Code sidebar for easy access
- Command Palette: Quick commands for generating from JSON files
Installation
- Install from VS Code Extensions marketplace or download the
.vsix file
- Reload VS Code
Usage
- Click the Mock Data Generator icon in the VS Code activity bar
- Choose between:
- Mock JSON: Paste your JSON schema and generate mock data
- Java Code: Generate Java test fixture code
Method 2: Using Command Palette
- Open a JSON file with your schema
- Press
Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (Mac)
- Choose:
- Generate Mock Data from JSON - Creates JSON mock data
- Generate Java Test Fixture from JSON - Creates Java test fixture code
{
"id": "number",
"name": "string",
"email": "string",
"phone": "string",
"createdAt": "date"
}
Generated Output
Mock JSON:
{
"id": 547,
"name": "John Doe",
"email": "john.doe@example.com",
"phone": "+1 (555) 123-4567",
"createdAt": "2025-02-20T14:30:22.123Z"
}
Supported Field Types
- Email: Fields containing "email"
- Phone: Fields containing "phone" or "mobile"
- Names: Fields containing "name", "firstname", "lastname"
- Addresses: Fields containing "city", "address", "street", "country"
- URLs: Fields containing "url" or "website"
- Dates: Fields containing "date", "created", "updated"
- IDs: Fields containing "id"
- Descriptions: Fields containing "description" or "comment"
Type-based Generation
string: Random words or sentences
number, int, integer: Random numbers between 1-1000
double, float: Random decimal numbers
boolean, bool: Random true/false values
Extension Settings
No settings required! The extension works out of the box.
Requirements
- VS Code 1.109.0 or higher
- Node.js (for development)
Development
Local Setup
- Clone the repository
- Run
npm install
- Press
F5 to open the extension development window
- Make changes and reload the window
Building
npm run compile # Compile TypeScript
npm run watch # Watch for changes
npm run lint # Run ESLint
npm run test # Run tests
Note: The npm run watch task should be running whenever you develop this extension. It automatically compiles your TypeScript code to JavaScript as you save changes. VS Code will start this task automatically when you load the extension development window, but you can also start it manually with npm run watch or by pressing Cmd+Shift+B (Mac) / Ctrl+Shift+B (Windows/Linux).
Packaging
npm install -g vsce
vsce package
Known Limitations
- Maximum 100 mock objects per generation
- Nested objects and arrays are supported
- Java code generation uses Jackson library for parsing
Release Notes
0.0.1
Initial release with core features:
- Mock JSON data generation
- Java test fixture code generation
- Webview UI interface
- Command palette integration