- In this lightning demo I will showcase how Codium, a cutting-edge generative AI tool, is revolutionizing code integrity. We will demonstrate Codium's ability to generate useful Mocha tests, taken from a public repository and highlight the seamless integration. You can see Codium as it transforms complex test scenarios into actionable insights, propelling code coverage forward. Join us for an insightful peek into the future of automated testing where speed meets quality!
Code coverage with AI
AI Generated Video Summary
Codium is a generative AI assistant for software development that offers code explanation, test generation, and collaboration features. It can generate tests for a GraphQL API in VS Code, improve code coverage, and even document tests. Codium allows analyzing specific code lines, generating tests based on existing ones, and answering code-related questions. It can also provide suggestions for code improvement, help with code refactoring, and assist with writing commit messages.
1. Introduction to Codium and Demo
Hello, welcome everyone. I'm Jaap from the Netherlands, representing Codium. We offer a generative AI assistant that integrates with your IDE, providing test generation, code explanation, and collab features. Our open source project, PR Agent, automates commit messages, PR reviews, and descriptions. Let's dive into a demo of Codium's capabilities by generating tests for a GraphQL API in VS Code. We can configure the test framework, libraries, and the number of tests to generate. We can also add prompts and use existing tests as examples. With Codium, we can generate tests and even document them. Let's address code coverage for the Express REST API server using Codium.
Hello, welcome everyone. So my name is Jaap, and as you can probably tell, I'm not from around here. I'm based out of the Netherlands. A little bit about myself, about how you can connect to me, but let's get into it and talk about the awesome things we do at Codium and how we can make your life easier.
So what Codium offers is we are a generative AI assistant that integrates in your IDE. So there can either be a VS Code, can be the JetBrains suite, and it offers test generation, code explanation, some collab features like no longer having to write your own pull requests. And we also have an open source project that one's called PR Agent. So PR Agent also has that functionality. It's completely free to use. URL is listed there. And you can either run it as a GitHub action or self host it, can connect to three of them listed here, GitHub, GitLab, Bitbucket, but it also works with Azure DevOps, CodeCommit, and I'm forgetting some others. So if you don't like writing your own commit messages, doing your own PR reviews, and writing your descriptions, PR Agent is a nice open source tool that we have at Codium.
And with that, I'd like to go into a demo. And I opted for the easy approach, zero demo failure. So I'm just going to dive into a couple of screenshots here that show some of the capability we have. And in order to do so, we're going to take a look at this repository. So this Mocha repository with a bunch of demo applications. And we're going to take a look at this GraphQL API. And we're going to see if we can generate some tests with it and show what the interface looks like for Codium. So this is in VS Code. And as you can see, there's a number of things that we can configure here. So we can select the test framework, we can select additional libraries, we can set how many tests we want to generate, we can also add prompting. And if you already have existing tests, you can also give a reference test example that we can use as a baseline to generate those tests. So what we can see here is I've generated one test. And I thought, well, it would be nice if the test was also documented. So I give a prompt, add a doc string. And then we can see that it also added a doc string to the test. Next up, I ran the code coverage for this repository. And I identified that Express REST API server did not have enough code coverage. So let's take a look at how we can solve this using Codium.
2. Code Explanation and Test Generation
Here's the code we're working with. Line numbers 16, 21, and 22 are not covered by code coverage. The code explanation provides a summary, example usage, and flow. Codium allows analyzing specific methods, functions, or lines. We can add more tests using existing tests as a reference. We can select appropriate behaviors and generate tests. We generated a test for the 404 error, which improved code coverage. Prompting Codium AI generated a test for the error code 500. We can regenerate results and use chat commands.
So here's the code that we're working with. I'll just go back one. We can also see the line numbers here. So we'll refer to that when we are looking at the source code. So we can see that line number 16, so the 404, was not covered with code coverage, according to code coverage. And also 21 and 22. So a server error was also not covered.
To get a better understanding of how we can generate these tests, we can take a look at the code explanation. So it gives a summary. It gives an example usage, and also the flow of how this piece of code works. So in this case, we're looking at a single file. But with Codium, you can also specify a specific method, a specific function, or a number of selected lines that you want to analyze or generate tests for or create doc strings for.
So next up, we can see the existing test. And what we're going to do, because we already have existing tests that cover the main part of the behavior, we're going to click the button that says, add more tests. So we will generate tests, and we will use the existing tests as a reference to generate those tests from. And we can see that we have a behavior analysis of this function. This is a pretty simple function. So not all these behaviors make complete sense, but that's the idea. You can select which ones you think are appropriate and then generate tests for those. Also have an option to generate the tests ourselves.
So in this case, we generated the one for the 404 error. And after adding that to the repository, rerunning the code coverage, we can see that now line number 16 is also covered. So great. There was no test, however, for the error code 500. And there was also no behavior for that. So I prompted Codium AI to generate the test for error code 500. And that way you can also generate those tests. And for any of the results that we generate, we can click regenerate to see what kind of to have it generate new code. We can do prompting to improve the code and to kind of guide it to the end goal. And we also have a number of chat commands integrated.
3. Code Questions and Communication
You can ask Codium AI questions about your code and even request it to generate mock data. It can improve certain parts of your code and provide multiple suggestions. You can also prompt it to refactor your code, review your changes, and help with writing commit messages. If you have any questions or want to get in touch, you can find me on Twitter or in the Codium AI Discord channel.
So it's possible to ask questions about your code. When asking questions, you can also ask it to generate mock data. We can see here that we have doc strings. We can improve the code. And when you ask it to improve, you can also prompt it. So it will improve certain parts of your code. And it will give multiple suggestions.
You can tell it to refactor it. It will give you a diff. And then you can choose to either accept it or to reject those changes. And once you get to the point where you are happy with your changes, Codium AI can also help you with writing your commit message. Before you push your code to a remote repository, you can already do a review of your changes against specific branches that you might want to push against to get an idea if you didn't make an oopsie and put an API token in there.
And with that, if you have any questions, I'm still on Twitter because I didn't get an invite for any of the others. You can reach me there. Or go to Codium AI. We have a Discord channel and that's probably the easiest way to get in touch. I'm the only Jaap there. So it's pretty easy.