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.

Generate <span class="gradient-text">Tests<span>

Getting Started

To start generating test suits, click buttons/clickable texts in one of the options below.
1

Above a class or a function:

You can click the text "Generate tests for the below function" on top of your class or function.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
2

From the qodo left panel:

Click the qodo button on the left pane, and the qodo pane will appear on the left. All the functions in your file will be displayed, and you can select the function you want to test.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
3

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.
VS Code
qodo - VS Code

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.

VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA

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

VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA

qodo allows you to customize your test suite as you need in the "Configuration" section.

1

You can: Choose a testing framework

You can choose your testing framework (unit test, pytest, etc.).

  1. Click the drop-down to view the options.
  2. Select your desired testing framework in the menu.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
2

Add example test

Adding a sample test will enable qodo to familiarize itself with your test case writing style and generate test cases that align with it.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
3

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.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
4

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.

  1. Click the dropdown.
  2. Select the number of test cases.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
Note

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

qodo provides several options to improve your tests to have a better output. You can:
1

Chat with TestGPT

You can suggest changes to a test code by chatting with the TestGPT model. You can follow the two steps below.

  1. Type the changes to be added for the test code in the chat box.
  2. 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.

VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA

You can view the previous results by clicking the previous and next buttons on the top left corner

2

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

  1. Clicking on the edit icon left of the objective.
  2. Enter your desired name and objective in the appeared text boxes.
  3. 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.

VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA
3

Regenerate Single Test

If you want the TestGPT model to generate an alternative code for a single test, simply click on the “Regenerate” button, and a new test code will be generated. You can swipe between the code versions with the previous and next buttons in the top left corner.
VS Code
qodo - VS Code
4

Get more tests

If you need more test cases other than the provided cases, you can create more test cases. You can click the "Give me more tests" button, and you'll have your extra test cases within a short time.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA

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.

5

Delete 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.
VS Code
qodo - VS Code
JetBrains - IntelliJ IDEA
qodo - JetBrains - IntelliJ IDEA

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.

qodo

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.