VSCode extension to generate test data for your unit tests using ChatGPT 🤖
This package is a VS Code extension that uses ChatGPT to generate fixtures (testing data) from the selected type definition. It provides an easy way to generate test data for GraphQL APIs and can save developers a lot of time when writing tests.
It is not published on the VSCode marketplace yet, but you can install it locally by cloning the repository and following the vsc-extension-quickstart
guide.
- Open a new command palette (Ctrl+Shift+P) and type
Set API Key
to set your OpenAI API key. - Select a type/interface definition in your typescript code.
- Open a new command palette (Ctrl+Shift+P) and type
Create Fixture
to generate fixtures for the selected type definition. - Another way is to open the context menu (right click) on the type definition and select
Create Fixture
. - The generated fixtures will be written after the selected type definition.
Given the following type definitions:
type Job = {
id: number;
name: string;
description: string;
salary: number;
}
type JobList = Job[];
type Person = {
id: number;
name: string;
age: number;
jobs?: JobList;
}
It generates the following fixture:
const fixture: Person[] = [
{
id: 1,
name: 'John',
age: 32,
jobs: [
{
id: 1,
name: 'Software Engineer',
description: 'Develop software applications',
salary: 50000
},
{
id: 2,
name: 'Web Developer',
description: 'Design and develop websites and web applications',
salary: 40000
}
]
},
{
id: 2,
name: 'Jane',
age: 25
},
{
id: 3,
name: 'Jack',
age: 38,
jobs: [
{
id: 3,
name: 'Data Scientist',
description: 'Conduct data analysis and model development',
salary: 60000
}
]
}
];