• Что бы вступить в ряды "Принятый кодер" Вам нужно:
    Написать 10 полезных сообщений или тем и Получить 10 симпатий.
    Для того кто не хочет терять время,может пожертвовать средства для поддержки сервеса, и вступить в ряды VIP на месяц, дополнительная информация в лс.

  • Пользаватели которые будут спамить, уходят в бан без предупреждения. Спам сообщения определяется администрацией и модератором.

  • Гость, Что бы Вы хотели увидеть на нашем Форуме? Изложить свои идеи и пожелания по улучшению форума Вы можете поделиться с нами здесь. ----> Перейдите сюда
  • Все пользователи не прошедшие проверку электронной почты будут заблокированы. Все вопросы с разблокировкой обращайтесь по адресу электронной почте : info@guardianelinks.com . Не пришло сообщение о проверке или о сбросе также сообщите нам.

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

Sascha Оффлайн

Sascha

Заместитель Администратора
Команда форума
Администратор
Регистрация
9 Май 2015
Сообщения
1,480
Баллы
155
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.

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"));
}




}
`\

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:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.



I’d love to hear your thoughts!



Источник:

Пожалуйста Авторизируйтесь или Зарегистрируйтесь для просмотра скрытого текста.

 
Вверх Снизу