Published on: April 10, 2025
5 min read
Learn step-by-step how to add unit tests to a Java application using agentic AI (includes a video tutorial).

Assuring the quality of your applications via test-driven design, good code coverage, and issue detection is critically important to your customers and your reputation, but it can also be a time-consuming endeavor. GitLab Duo Workflow, agentic AI built on top of the most comprehensive DevSecOps platform, can help you quickly complete development tasks such as adding unit tests to a Java application. This tutorial demonstrates how by using this sample Java project.
GitLab Duo Workflow is currently in private beta. Join the waitlist to see what’s possible with AI agents that understand your entire SDLC.

Note: We are assuming that you already enabled the GitLab Duo Workflow extension in your VS Code. If not, please refer to the setup documentation.

Create unit tests for class defined in the Product.java file and store the unit tests in its own file titled ProductTest.java


src/test/java/csaa/jspring/ProductManager in the project with a new file in it named ProductTest.java, which contains all the unit tests for the Product.java class.
ProductTest.java and you will see that it has some import statements underlined in red indicating some import errors:
Let’s have GitLab Duo Workflow fix these for us.
Note: We could have also asked GitLab Duo Workflow in our first prompt to update the pom.xml file accordingly. But since we didn’t, let’s fix these errors in a new workflow.

The file ProductTest.java has an error “The import org.junit cannot be resolved”. Please fix it
pom.xml file. It then edits it and removes the outdated JUnit dependency, and follows that with the addition of the correct dependency and version for JUnit. Lastly, it reads the ProductTest.java file to clear all the dependency errors.
Through the execution of this plan, GitLab Duo Workflow is effectively making updates to the project to achieve what was requested in the prompt, saving time and effort, and increasing productivity so that developers can spend more time innovating and creating value for their organization.
If you’d like to see what you read above in action, watch the following video:
Sign up for the GitLab Duo Workflow private beta waitlist to see what’s possible with AI agents that understand your entire SDLC.
Enjoyed reading this blog post or have questions or feedback? Share your thoughts by creating a new topic in the GitLab community forum.
Share your feedback