AI Studio helps you with the power of chatGPT in many subjects such as adding unit tests, refactoring code, adding summary, etc. while writing code, just by right clicking on the code.
Get it from Visual Studio Marketplace
- First, you need to create an API key from the https://platform.openai.com/account/api-keys
- Go to Tools/Options/AI Studio page and write the key in the General section
- If you prefer refactoring the code changes, keep Format Changed Text as True.
- Choose a Language Model options: "ChatGPTTurbo", GPT4_Turbo, "GPT4", "GPT4o" or "GPT4_32k_Context"
Write a use case where you want to write the code, select the statement (if it's a single line just click on the line), right-click, and click "AI Studio / Code It".
Prints the result after a short time:
Select the lines of code you want to comment on, right-click, and click "AI Studio / Add Comments".
Returns the selected code with detailed comments.
Select the whole method, right-click, and click "AI Studio / Refactor".
The refactored result:
Select the whole method or just the first line of the method, right-click, and click "AI Studio / Add Summary".
Gives a very detailed and logical result:
Select the lines of code you want to explain, right-click, and click "AI Studio / Explain".
Shows a popup that includes explanations of the selected code:
- AI studio is a flexible tool that allows you to customize all commands. Go to Tools/Options/AI Studio/Commands,
- Write something to help chatGPT about the behaviors of the commands.
Then trigger the command again, and you will see the results affected by your comments:
Select the whole method, right-click, and click "AI Studio / Add Unit Tests".
Prints the unit test(s) based on your choices:
You can also customize the unit tests on Tools/Options/AI Studio/Unit Test
- Unit Testing Framework: Select unit testing framework to set up main functionalities.
- Isolation Framework: An isolation framework is a set of programmable APIs that makes creating fake objects much simpler, faster, and shorter than hand-coding them.
- Test/Dummy Data Framework: Test Data Builders and Dummy Data Generators.
- Fluent Assertions Framework: Fluent assertions frameworks is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit test.
- Customize: Add any other details to customize unit tests.
Select the code line(s), right-click, and click "AI Studio / Security Check".
Gives some information and suggestions: