Enhance Your Code: CodiumAI’s Automated Analysis and Suggestions for Python and JavaScript
Tags: programming, ai, javascript, python
Published: 2023-06-13 14:09:45


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1aw5iyy6vfrkhlnwm4h9.png)

Writing code tests plays a vital role in software development, guaranteeing high-quality code, early bug detection, and enhanced maintainability. Yet, this process often becomes a time-consuming and monotonous endeavor.

Developers frequently find themselves allocating considerable time to writing tests, diverting their attention from actual development. Fortunately, the progress in artificial intelligence (AI) has opened doors to automated test generation, presenting developers with an innovative method for creating code tests. One such tool is CodiumAI, which allows you to automatically generate tests for your code.

With CodiumAI, you receive meaningful and straightforward test suggestions directly within your integrated development environment (IDE), enabling you to write better code. Let’s see how we can use CodiumAI on VSCode and PyCharm.

I will be keeping it simple and will only focus on how CodiumAI can be used to do an analysis of the code and also get suggestions.

## How to Use CodiumAI to Generate Tests for Python

Let’s take a simple Python code to better understand how code analysis could be done using CodiumAI. The following function, ‘largest_prime_factor’ takes a number and tells the largest prime factor for that number.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fi4spnnjbn9dfditkay7.png)

For some people, this code could be difficult to understand. Along with that, this code is also not well-optimized. Let’s check out the analysis of the CodiumAI regarding our Python code.

Click on the ‘Generate tests for the below function’, to pop up the CodiumAI window. Once the CodiumAI tabs show up, click on the ‘Code Analysis’ tab.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpuxuk3v2c5nam2j11u3.png)

As the name suggests, the analysis tab provides a detailed analysis of the code. This covers objectives, inputs, flow, outputs, and a few additional aspects. Almost anyone can easily understand the code by just simply going through the analysis. This makes it easier for other programmers to understand the code and also contribute to it.

You can also improve your code with AI-generated suggestions. For suggestions, click on the ‘Code Suggestions’ tab to get suggestions from the CodiumAI.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sw5gakrp2n4pntuvjpwm.png)

Under the ‘Code Suggestions’ tab, you will see multiple suggestions. Each suggestion contains two things, first the actual suggestion, and second, how your code will be affected by following the suggestion.

Following are the few suggestions given by CodiumAI regarding our Python code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a1c725whk1mbrdh32zxr.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/py4halhjqwf3iu2l1wnp.png)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/362yd016tty8y5ajwepo.png)


To apply the suggestion, just click on the checkbox on the top left of each suggestion. After checking the box, click on the ‘Prepare Code Changes’ button at the bottom right of the window. You can also select all the suggestions by clicking on ‘Select All’, which is present at the bottom left of the window.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy355l9iz2iv9qjfo639.png)

Once you click on ‘Prepare Code Changes’ you will see a new window with the previous code along with the suggested changes for a better comparison. You can also see the list of suggestions that are being applied to the code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ztzd86jr348m8pgd0yt.png)

After that click on ‘Apply to my Code’ to apply the changes. Right after clicking, your code will magically change into a well-optimized, functional code. Just a few clicks, it’s that simple.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4jatsxeqndkbdnw85jfy.png)

## How to Use CodiumAI to Generate Tests for JavaScript

We have seen how we can get detailed suggestions for our Python code. Now let’s see how we can do the same with JavaScript.

I have taken an easy and basic example of a Fibonacci series generator in JavaScript. The following function generates n number of terms in Fibonacci Series.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7s05vzzt6qhd2vsutbk6.png)

Is our code perfect? I mean it does the job but is it really perfect? Let’s see what CodiumAI thinks about this.

Click on the ‘Generate tests for the below function’, to pop up the CoidumAI window. Once the CodiumAI tabs show up, click on the ‘Code Analysis’ tab.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4a54le68epa5v582shf6.png)

Once you click on it, a detailed analysis of the code is displayed. The analysis includes objectives, inputs, flow, outputs, and some additional aspects. As you can see in the screenshot, this is a pretty detailed analysis of such a small function that we wrote. Anyone can understand the code immediately by just going through the analysis. This might not look much helpful in this example that we are using, but this is very helpful once you are writing complex code. This makes it easier for others to understand your code.

This is the analysis part. The best thing is that we can get code suggestions for JavaScript too.

Click on the ‘Code Suggestions’ tab and you will be presented with some suggestions. The process is similar to what we followed for Python.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hhxuiu86phi1en2o2mx.png)

Under the ‘Code Suggestions’ tab, you will see multiple suggestions. Each suggestion contains two things, first the actual suggestion, and second, how your code will be affected by following the suggestion.

Following are the few suggestions given by CodiumAI regarding our JavaScript code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g1c50tmfyjne3am8w31e.png)

To apply the suggestion, just click on the checkbox on the top left of each suggestion. After checking the box, click on the ‘Prepare Code Changes’ button at the bottom right of the window. You can also select all the suggestions by clicking on ‘Select All’, which is present at the bottom left of the window.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2jq1225r1zactu62ov1w.png)

Once you click on ‘Prepare Code Changes’ you will see a new window with the previous code along with the suggested changes for a better comparison. You can also see the list of suggestions that are being applied to the code.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gcqno7njfnvd4yaedoul.png)

After that click on ‘Apply to my Code’ to apply the changes. This will convert your code into a well-optimized, readable code. I bet you haven’t seen an easier method of code refactoring than this!


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5i4pl9dvwq33vv7s9d2.png)

As you can see CodiumAI is quite nice if it comes to code analysis and suggestions too. I found this feature by accident, and already using it often. Do you use any AI tools to improve your coding? Let me know about it, and what do you think about CodiumAI!

**Subscribe for more coding articles and tools!**