DEV Community

rajeev
rajeev

Posted on • Edited on

Automating Unit Test Generation in Java: Why I Built My Own Tool

Like many Java developers, I’ve spent a good chunk of my career writing unit tests. It’s necessary work, but honestly—it often feels repetitive and mechanical.

Over time, I realized that I wasn’t learning much from writing the similar variation of the same kind of test. What I really wanted was to spend my energy on solving actual business problems, not boilerplate testing code.

That got me thinking: what if I could automate most of this?


Why I Started This Project

I’ve tried tools like Copilot, and while they’re powerful, they’re also very generic. They can generate a test here and there, but they aren’t really focused on the unit testing problem.

They don’t respect your team’s naming conventions, they sometimes miss edge cases, and they don’t give you much control.

So I decided to build a tool with a narrow focus: unit test generation for Java projects, starting with JUnit 5.


What It Does So Far

  • Generates JUnit tests from your Java code
  • Lets you define your own test naming pattern (so tests look like the ones your team already writes)
  • Allows you to choose the test framework (starting with JUnit 5, with more coming soon)
  • No need to write any prompts

The idea is not to replace tests completely, but to remove the same repetitive work and also no prompts writing so developers can focus on meaningful scenarios.


Demo: See the AI Unit Test Generator in Action

Watch this short demo to see how our tool automatically generates Java unit tests with custom patterns.

AI Unit Test Generator Demo


👉 Ready to try it yourself?

Join the waitlist here: https://theproj.xyz


Example

Here’s a small example of what the tool generates:

\`java

Input java source code:
public class StringUtils {
public boolean isPalindrome(String str) {
String reversed = new StringBuilder(str).reverse().toString();
return str.equals(reversed);
}
}
Output java tests generated:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

public class StringUtilsTest {

@Test
public void testIsPalindrome_WhenPalindrome_ShouldReturnTrue() {
    StringUtils stringUtils = new StringUtils();
    assertTrue(stringUtils.isPalindrome("madam"));
}

@Test
public void testIsPalindrome_WhenNotPalindrome_ShouldReturnFalse() {
    StringUtils stringUtils = new StringUtils();
    assertFalse(stringUtils.isPalindrome("hello"));
}

@Test
public void testIsPalindrome_WhenEmptyString_ShouldReturnTrue() {
    StringUtils stringUtils = new StringUtils();
    assertTrue(stringUtils.isPalindrome(""));
}

@Test
public void testIsPalindrome_WhenSingleCharacter_ShouldReturnTrue() {
    StringUtils stringUtils = new StringUtils();
    assertTrue(stringUtils.isPalindrome("a"));
}
Enter fullscreen mode Exit fullscreen mode

}
`\

Following are some screenshots from the tool



What’s Next

I’m still actively working on it, and I’d really like feedback from other Java developers:

  • Would you find something like this useful in your workflow?
  • What’s missing that you’d want before you’d actually use it in a real project?

If you’re curious to try it out I am planning to put it in simple site in a week. For more info you can check my page as well: https://theproj.xyz/

I’d love to hear your thoughts!

Top comments (0)