Generate tests for Code Behavior.

Once you have generated some tests for your code, CodiumAI allows you to explore and understand your code's behavior. This process involves executing the tests and observing how the code responds to different inputs and conditions.
Generate tests for <span class="gradient-text">Code Behavior.<span>

What is Code Behavior?

Code behavior refers to how a specific code operates and responds to different inputs and conditions.
It describes how the code executes instructions and produces output based on its design and logic.

To demonstrate this feature, an example will be used.

VS Code
Codium - VS Code

Example: The test cases will be generated for four Python functions which take two inputs and add, subtract, multiply, and divide them and return the value.

Getting Started

In the CodiumAI panel, you can see the "Behaviors Coverage" section under the "Configuration" section.
Through this section, you can gain information about the behavior of your code.
VS Code
Codium - VS Code
JetBrains
Codium - JetBrains
1

It mainly provides the below information.

Total Behaviors: This refers to the number of ways your code can behave with various inputs and conditions.

Current Coverage: This gives you information about how many code behaviors were covered through the generated test cases.

CodiumAI identifies 15 code behaviors in the given example, and the generated tests have covered only 8 of them.

Other than these insights, you can click the drop-down icon to have information about all the possible behaviors of your code.

VS Code
Codium - VS Code
JetBrains
Codium - JetBrains
2

For the given example, the identified code behaviors have been listed under 2 test types and the rest under "Other."

Each is categorized under test types such as Edge Case, Happy Path, etc. Also, based on the generated tests, each behavior is evaluated and classified as either covered or not covered.

Every covered behavior has a drop-down next to the word "Covered." By clicking, you can see the test case, which has covered the corresponding code behavior.

VS Code
Codium - VS Code
JetBrains
Codium - JetBrains

As shown above, the code behavior "Test adding two positive numbers" has been covered by the test case "test_add_positive_numbers."

For uncovered behaviors, CodiumAI has provided you the ability to generate tests by simply clicking the Generate test button.

VS Code
Codium - VS Code
JetBrains
Codium - JetBrains

Here, it generates a test case to cover the "divide numbers with negative integers" behavior.

After generating the tests, you can click the refresh button for the latest update about the number of covered code behaviors.

VS Code
Codium - VS Code
JetBrains
Codium - JetBrains

As in the example, it had 8 code behaviors covered in the beginning. After generating a test to cover one uncovered behavior and clicking the "Refresh" button, it updates the "Current Coverage."

Automatically updates the "Current Coverage"

Generate tests for sub-behaviors in the code

CodiumAI allows you to explore sub-behaviors of your class and generate test cases to cover only them.

  1. Select the part of the code you need to cover.
  2. Repeat the above process.

The feature is still in its early stages, but it can be a valuable tool for developers as it can help developers save time, improve the quality of their code, and catch bugs early.

CodiumAI

Check out other features

Gain insights into the range of innovative features that CodiumAI brings to your development toolkit, all designed to ensure superior code integrity and efficiency.