Generate Tests
Qodo allows you to generate a comprehensive test suite for various types of code, including classes, functions, and code snippets. It assists you by automating the test creation process, saving time and effort.
Whether you need to test a specific class, a function, or a small section of code, Qodo offers the functionality to generate meaningful test cases that can ensure the quality and reliability of your code.
Getting Started
Above a class or a function:
From the qodo left panel:
Select a code snippet, right-click, and click the "qodo - Generate tests" button.
Note: Currently available only on VS Code editor.
Alternatively, you can select the code block you want to test and right-click it. Then a menu pane will pop up, and select the "qodo - Generate tests" option.After using one of those options, it will take a short processing time, and then you'll be directed to the qodo editor, where a test suite with some suggested tests will be provided to you.
If you scroll down, you can see various test cases provided by qodo, each including a name, objective, a tag that indicates the test type (Happy Path, Edge Case, etc.), and the relevant test code.
Customizing the test suite
qodo allows you to customize your test suite as you need in the "Configuration" section.
You can: Choose a testing framework
You can choose your testing framework (unit test, pytest, etc.).
- Click the drop-down to view the options.
- Select your desired testing framework in the menu.
Add example test
Add mocks
Mocks replace actual implementations with simplified or controlled versions, enabling more focused and isolated testing of specific functionalities.
You can toggle the auto-mock button to enable/disable the ability to add mocks automatically.Select the number of tests.
qodo allows you to change the number of test cases you need for your code. The number of test cases can be chosen from 1 to 12.
- Click the dropdown.
- Select the number of test cases.
Sometimes, errors can occur related to your testing framework when you use it for the first time. Installation of it may be required on your system to proceed with its usage.
After configuring your test suite, click the "Regenerate" button to regenerate the test cases with the changes.
Enhance your tests
Chat with TestGPT
You can suggest changes to a test code by chatting with the TestGPT model. You can follow the two steps below.
- Type the changes to be added for the test code in the chat box.
- Click the send button / click “Enter.”
Then it will process the input and update the test code for you.
Example: Suggesting 6 and 4 as inputs instead of 2 and 3 by chatting with the TestGPT model.
You can view the previous results by clicking the previous and next buttons on the top left corner
Customize the name and objective of a test
qodo allows you to change the name and objective of the test function. You can customize them by
- Clicking on the edit icon left of the objective.
- Enter your desired name and objective in the appeared text boxes.
- To apply the changes, click the "Regenerate" button.
Now you'll get the updated test code with the relevant changes.
Example: Changing the name (as test_with_all_zeros) and the objective (as This test will add two zeros and return the value 0) of the test code.
Regenerate Single Test
Get more tests
There can be test cases you don't need anymore. qodo enables you to delete them from the test suite. Click the "Delete" button in the test case you want to remove.
Delete tests
After completing your test suite, you can run the tests to evaluate whether they pass or fail, ensuring the functionality and correctness of your code. Refer to the "Run Tests" feature to see the specific instructions on running tests in qodo.
After reaching a satisfactory state with your test suite, you can save it to a file, and you are good to go! Keeping your test suite ensures you have a documented record of your tests, allowing you to reference and execute them in the future quickly.
Check out other features
Gain insights into the range of innovative features that qodo brings to your development toolkit, all designed to ensure superior code integrity and efficiency.