Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>GPT Unit TestNew to Visual Studio Code? Get it now.
GPT Unit Test

GPT Unit Test

chenzhenmin

|
239 installs
| (0) | Free
Unit Test Automatic Generation Plugin Based on GPT-3.5 Model
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

GPT - Unit Test

这是一个基于 OpenAI Chatgpt(GPT - 3.5) 模型开发的单元测试自动生成插件 demo 体验版。

使用这个插件前,你需要配置你的 openAI key, 并保证其中有足够的额度可以完成单元测试的自动生成(一个生成有效单元测试的文件将等同于消耗一次 chatGpt 额度)。

请关注 openAI 的隐私性问题,所有被自动生成用例的文件都会将代码文件上传到训练集,请避免使用非个人代码或非公开代码测试!

安装

在安装使用插件前,请保证 vscode 的 engines 版本大于等于 1.77.0, 并配置好代理和虚拟 ip 等访问 openAi 的前置操作,避免 openAi 的请求超时或中断

除此之外,你只需要在 vscode extensions 中搜索 ChatGPT - UI Unit Test 即可完成插件的安装,在使用 & 配置项的模块会分别说明

  • 如何给你的项目使用 ChatGPT - UI Unit Test
  • 如何做出一些自定义的扩展配置

使用

GPT - Unit Test 的使用很简单,在从 vscode extensions 中完成安装后,所有文件夹和文件都有提供生成单元测试的入口,你只需要右键选择 generate unit test 即可使用插件

如果你没有配置你的 openApi key,那么会自动弹窗要求你填入,并在每次生成单元测试前,将自动完成 key 的合法性和额度有效验证,不需要你额外进行任何操作,你只需要:

  • 选择需要生成的文件
  • 点击 generate unit test

当然,可能你还需要针对你的项目配置一些自定义的内容,比如单测的文件格式,需要忽略的内容,使用的测试技术栈等,这些我们将在配置项进行详细说明

配置项

下面是 GPT - Unit Test 目前提供的所有配置项

参数名称 是否必填 参数类型 参数作用
gptUnitTest.openApiKey 是 string Chatgpt openapi key,用户态登录用
gptUnitTest.ignoreDocument 否 string[] glob 表达式数组,需要忽略的文件目录
gptUnitTest.supportedFileExtensions 否 string 会转换为正则,支持的文件后缀,默认 js,jsx, ts, tsx
gptUnitTest.testingLibrary 否 string 'enzyme' 或 'react testing library' 或 'mocha'
gptUnitTest.testDirectory 否 string 测试目录,写入文件时将在对应文件同级目录下创建对应命名文件夹,用于存放测试用例,默认值为tests
gptUnitTest.testFileSuffix 否 string 写入的测试文件中间缀,默认 test , 即写入的测试文件将为 xx.test.ts(x)
gptUnitTest.temperature 否 number temperature 是用于控制“创造性”的一个参数。它的值通常设置在 0 到 1 之间,默认设置为 0.6。需要注意的是,这个值越高,用例会越复杂,语法错误的可能性也会越高,而值越低用例则相对简单,越趋近开箱即用,可以根据自己的需求设置合理的值。

贡献 & issue

目前还没有提供插件的贡献方式,短期和未来也许也不会有,插件并没有太多复杂的逻辑,除 openAI 流式接入外,剩下的主要是一些内容的字符提取和文件 I/O 逻辑

目前 GPT - Unit Test 还是一个 MVP 版本,没有经历过太多项目的验证与测试,如果你在使用阶段遇到了预期之外的问题或者体验上的优化调整,可以通过邮件(12904333700@qq.com)的方式或者 通过掘金私信我(https://juejin.cn/user/2714061017452557) 我改正, 为了提高解决问题的效率,希望可以提供以下信息帮助排查:

  • 问题的复现方式
  • 出问题的业务代码(如果方便提供的话)
  • 你的个人联系方式(如果方便提供的话)

收到问题后,我会在三个工作日内处理,并且给你答复,感谢对 GPT - Unit Test 的试用与支持!

GPT - Unit Test

This is a demo version of the unit test automatic generation plugin developed based on the OpenAI Chatgpt (GPT -3.5) model.

Before using this plugin, you need to configure your openAI key and ensure that there is enough quota to complete the automatic generation of unit tests (a file that generates valid unit tests will be equivalent to consuming one chatGpt quota).

Please pay attention to the privacy issues of openAI. All files that are automatically generated into use cases will upload the code files to the training set. Please avoid using non personal or non-public code for testing!

Installation

Before installing and using the plugin, please ensure that the engines version of vscode is greater than or equal to 1.77.0,and configure the proxy and virtual IP to access the pre operation of openAi, to avoid timeout or interruption of openAi requests

In addition, you only need to search for ChatGPT - UI Unit Test in vscode extensions to complete the installation of the plugin. The modules using the&configuration items will be explained separately

  • How to use ChatGPT - UI Unit Test for your project

  • How to make some custom extension configurations

Using

The use of GPT - Unit Test is very simple. After installation from vscode extensions, all folders and files have an entry point for generating unit tests. You only need to right-click and select Generate Unit Test to use the plugin

If you have not configured your openApi key, it will automatically pop up and require you to fill it in. Before each unit test is generated, the legality and validity of the key will be automatically verified. No additional actions are required, you only need to:

  • Select the file to be generated

  • Click on generate unit test

Of course, you may also need to configure some custom content for your project, such as the file format for single testing, the content to be ignored, the testing technology stack used, etc. We will provide detailed explanations in the * _ Configuration Item _ *

Configuration Item

The following are all the configuration items currently provided by GPT - Unit Test

Parameter Name Required Parameter Type Parameter Function
GptUnitTest. openApiKey Yes string Chapter openAPI key, used for user login
GptUnitTest. ignoreDocument No string [] Global expression array, file directory to ignore
GptUnitTest. supportedFileExtensions No string Will be converted to regular, supported file suffixes, default js, jsx, ts, tsx
GptUnitTest. testingLibrary No string 'enzyme 'or' react testing library 'or' mocha '
GptUnitTest. testDirectory No string Test directory. When writing files, a corresponding named folder will be created in the same level directory as the corresponding file to store test cases. The default value is * _ tests _ *
GptUnitTest. testFileSuffix No string The middle suffix of the written test file, which defaults to test, means that the written test file will be xx. test. ts (x)
GptUnitTest. characteristic No number temperature is a parameter used to control 'creativity'. Its value is usually set between 0 and 1, with a default setting of 0.6. It should be noted that the higher the value is, the more complex the instance will be, and the higher the possibility of syntax error will be. The lower the value is, the simpler the use case will be, and the closer it is to out of the box use. You can set reasonable values according to your own needs

Contribution&Issue

At present, there is no way to provide a contribution method for plugins, and there may not be any in the short term or in the future. Plugins do not have much complex logic, except for openAI streaming access, the rest is mainly about character extraction and file I/O logic for some content

At present, GPT - Unit Test is still an MVP version and has not undergone much project validation and testing. If you encounter unexpected problems or experience optimization adjustments during the use phase, you can send them via email( 12904333700@qq.com )Either by digging gold or sending me private messages( https://juejin.cn/user/2714061017452557 )I have corrected and in order to improve the efficiency of problem-solving, I hope to provide the following information to assist in troubleshooting:

  • How to reproduce the problem
  • The problematic business code (if convenient to provide)
  • Your personal contact information (if convenient)

After receiving the question, I will handle it within three working days and give you a response. Thank you for your trial and support of GPT - Unit Test!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft