Code coverage with AI

Rate this content
Bookmark
  • 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!
8 min
07 Dec, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

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.

Available in Español

1. Introduction to Codium and Demo

Short description:

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

Short description:

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

Short description:

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.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

JSNation 2023JSNation 2023
24 min
AI and Web Development: Hype or Reality
In this talk, we'll take a look at the growing intersection of AI and web development. There's a lot of buzz around the potential uses of AI in writing, understanding, and debugging code, and integrating it into our applications is becoming easier and more affordable. But there are also questions about the future of AI in app development, and whether it will make us more productive or take our jobs.
There's a lot of excitement, skepticism, and concern about the rise of AI in web development. We'll explore the real potential for AI in creating new web development frameworks, and separate fact from fiction.
So if you're interested in the future of web development and the role of AI in it, this talk is for you. Oh, and this talk abstract was written by AI after I gave it several of my unstructured thoughts.
React Summit US 2023React Summit US 2023
30 min
The Rise of the AI Engineer
We are observing a once in a generation “shift right” of applied AI, fueled by the emergent capabilities and open source/API availability of Foundation Models. A wide range of AI tasks that used to take 5 years and a research team to accomplish in 2013, now just require API docs and a spare afternoon in 2023. Emergent capabilities are creating an emerging title: to wield them, we'll have to go beyond the Prompt Engineer and write *software*. Let's explore the wide array of new opportunities in the age of Software 3.0!
JS GameDev Summit 2023JS GameDev Summit 2023
37 min
Building the AI for Athena Crisis
This talk will dive into how to build an AI for a turn based strategy game from scratch. When I started building Athena Crisis, I had no idea how to build an AI. All the available resources were too complex or confusing, so I just started building it based on how I would play the game. If you would like to learn how to build an AI, check out this talk!
React Summit 2023React Summit 2023
29 min
Improving Developer Happiness with AI
GitHub Copilot is an AI pair programmer that can help you write code faster and spend less time writing repetitive code.This session will cover some interesting use cases for Copilot that could shine a light on its possibilities. This ranges from prompting Copilot to suggest a function based on a comment, learning how to use a new framework, tackling a security or accessibility bug, better documenting your code, translating  code from one language to another, etc.Agenda:
Introduction to CoPilot
- What is Copilot
- How can you use it
- How it can help you write code faster
- Copilot Labs experimental features I will pick examples from the React ecosystem and show how we can fix Security Vulnerabilities and Accessibility issues in some components.

Workshops on related topic

DevOps.js Conf 2024DevOps.js Conf 2024
163 min
AI on Demand: Serverless AI
Featured WorkshopFree
In this workshop, we discuss the merits of serverless architecture and how it can be applied to the AI space. We'll explore options around building serverless RAG applications for a more lambda-esque approach to AI. Next, we'll get hands on and build a sample CRUD app that allows you to store information and query it using an LLM with Workers AI, Vectorize, D1, and Cloudflare Workers.
React Advanced Conference 2023React Advanced Conference 2023
98 min
Working With OpenAI and Prompt Engineering for React Developers
Top Content
Workshop
In this workshop we'll take a tour of applied AI from the perspective of front end developers, zooming in on the emerging best practices when it comes to working with LLMs to build great products. This workshop is based on learnings from working with the OpenAI API from its debut last November to build out a working MVP which became PowerModeAI (A customer facing ideation and slide creation tool).
In the workshop they'll be a mix of presentation and hands on exercises to cover topics including:
- GPT fundamentals- Pitfalls of LLMs- Prompt engineering best practices and techniques- Using the playground effectively- Installing and configuring the OpenAI SDK- Approaches to working with the API and prompt management- Implementing the API to build an AI powered customer facing application- Fine tuning and embeddings- Emerging best practice on LLMOps
JSNation Live 2021JSNation Live 2021
81 min
Intro to AI for JavaScript Developers with Tensorflow.js
Workshop
Have you wanted to explore AI, but didn't want to learn Python to do it? Tensorflow.js lets you use AI and deep learning in javascript – no python required!
We'll take a look at the different tasks AI can help solve, and how to use Tensorflow.js to solve them. You don't need to know any AI to get started - we'll start with the basics, but we'll still be able to see some neat demos, because Tensorflow.js has a bunch of functionality and pre-built models that you can use on the server or in the browser.
After this workshop, you should be able to set up and run pre-built Tensorflow.js models, or begin to write and train your own models on your own data.