Skip to main content

Codium.AI - a tool to generate tests

Codium.AI is a VSCode extension powered by GPT models to generate test, code explanation and refactoring suggestions.

It can be installed here: https://www.codium.ai/install/vs-code/ A GitHub account is needed to use it.

Pasted image 20230626160620.png

It generates decent tests, but without using our testing wrappers like renderWithProvider.

As it does not integrate well with our testing stack, it is not usable to write integration tests (which constitute the majority or our tests)

Pasted image 20230626160839.png However, it really shines when it comes to unit tests. It generates multiple tests for each function that cover multiple cases.

It also provides a "code analysis" which summarized the purpose of the function, it's argument and it's logic Below is an excerpt of the analysis. The full analysis is lengthy and verbose

The objective of the adaptChartData function is to transform the data points of a ChartData object into a format suitable for chart rendering, by mapping the values to the y-axis and the dates to the x-axis, relative to a given start date.

It also provides code suggestions like renaming some variables for more clarity

Suggestion: Rename 'adaptChartData' to 'convertChartData'

Why: The name 'convertChartData' better reflects the purpose of the function, which is to convert the input data to a different format.

Base Code:

// line number: 8
export const adaptChartData = (data: ChartData, startDate: Date) => {
const adaptedData = data.points.map((value) => ({
y: value.value,
t: differenceInDays(value.date, startDate) + 1,
}));
return adaptedData;
};

The suggestions are not amazing but they could be useful to find better names for function or bugs in some cases.

Behaviors and Edge cases​

Capture d’écran 2023-06-27 à 11.51.34.png Capture d’écran 2023-06-27 à 12.00.59.png

Code Analysis​

Capture d’écran 2023-06-27 à 11.56.57.png

Suggestions​

Capture d’écran 2023-06-27 à 11.59.16.png Capture d’écran 2023-06-27 à 12.00.21.png

Why it is KO : Examples of incompatibilities with our test files :​

CodiumBAM
![Capture d’écran 2023-06-26 à 17.10.34.png](/Assets/Capture d’écran 2023-06-26 à 17.10.34.png)Capture d’écran 2023-06-26 à 17.08.45.png
CodiumBAM
![Capture d’écran 2023-06-26 à 17.09.58.png](/Assets/Capture d’écran 2023-06-26 à 17.09.58.png)Capture d’écran 2023-06-26 à 17.13.47.png

Cannot enter the components

Other issue : Capture d’écran 2023-06-27 à 12.19.29.png Sends all the data to the codium servers Capture d’écran 2023-06-27 à 14.49.16.png

Conclusion​

Pros :

  • analyses behaviors and edge cases
  • generates a complete test file with description, flow etc
  • gives good structure for the tests
  • gives good results for unit tests

Cons :

  • cannot enter inside the components