Skip to content

ai4devops/Java-TestWithAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ§ͺ Generating Unit Tests with Generative AI

πŸ‘€ Overview

This repository is designed to help developers practice and improve their skills in implementing unit tests and test-driven development (TDD) using generative AI. Through practical exercises, organized in folders, developers will learn how AI can facilitate the creation, refinement, and optimization of unit tests for their daily projects.

πŸ‘€ Audience

This repository is for developers of all levels who want to integrate generative AI tools into their workflow, with a particular focus on unit testing and TDD practices.

πŸ› οΈ How to Use This Repository

The various exercises in this workshop are all located in the exercises folder, each with its own README. Each exercise is in a sequentially numbered folder (01, 02, 0n...), followed by the word exercise. For example, the first exercise is in the ./exercises/01_exercise folder. Answers to the exercises are available in the answers directory.

To clone this project, use the following command:

git clone <ADD FINAL REPO URL HERE>

Then, navigate to the desired exercise folder:

cd ./exercices/01_exercice1

Next, install the necessary dependencies:

mvn clean install

Run the tests with:

mvn test

🧩 Exercise Structure

To work on an exercise, switch to the corresponding folder and follow the instructions in the README or comments in the code. Based on your knowledge and what you want to deepen, feel free to move between exercises that you find relevant.

1. πŸ”€ StringHelper | 01_exercice | ~15 minutes

Implement unit tests for three predefined methods using generative AI suggestions. The tests should be written in the StringHelperTest class. Verify their validity with:

mvn test

2. ⏳ FormatDateTimeHelper | 02_exercice | ~20 minutes

Implement the formatDate and formatDateTime functions by following the tests in the DateTimeHelperTest file. This exercise emphasizes the application of TDD with AI. Enhance the tests as needed to reinforce validations.

3. πŸ‘₯ CRM Application | 03_exercice | ~20 minutes

In this exercise, you will work on a customer account management application with a UserRepository for retrieving users and a service providing find and create functions. Write unit tests covering these functions and their edge cases by mocking UserRepository calls.

πŸ“ˆ Goals and Purpose of the Exercises

πŸ“ Exercise 1, Unit Testing: This exercise introduces you to using AI to generate effective unit tests. By automating test creation, developers can focus on code quality and explore edge cases. AI handles test creation tasks, enabling a more robust testing process and enhancing productivity.

🧩 Exercise 2, TDD: This exercise explores TDD practice with generative AI, demonstrating how AI can iterate from tests to produce functional code and ensure its compliance with various scenarios defined in the unit tests.

πŸ€– Exercise 3, Unit Tests with Mocking: This exercise highlights the use of mocks to simulate repository calls. It covers potential application states, such as successful data retrieval and error handling. This exercise helps developers use AI to identify and cover all potential cases, making software more resilient and reliable.

🎯 Conclusion

By completing these exercises, you will not only improve your unit testing skills but also discover how AI can become a powerful ally in software development. Each exercise has a answer directory that you can refer to if you need help or have exceeded the allotted time.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages