Skip to content

Diplom1#1267

Open
AnzhelikaZimina wants to merge 2 commits intoyandex-praktikum:mainfrom
AnzhelikaZimina:develop1
Open

Diplom1#1267
AnzhelikaZimina wants to merge 2 commits intoyandex-praktikum:mainfrom
AnzhelikaZimina:develop1

Conversation

@AnzhelikaZimina
Copy link

Добавлены unit-тесты для класса Burger + настройка покрытия JaCoCo. Использованы JUnit 4, Mockito, параметризованные тесты. Подключён JaCoCo для анализа покрытия, результат:
Покрытие тестами класса Burger: 100%

}

@Test
public void testGetReceipt_ReturnsCorrectReceipt() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Неверный нейминг. Не используем спецсимволы в названии методов


@Test
public void testGetReceipt_ReturnsCorrectReceipt() {
Bun bun = new Bun(bunName, bunPrice);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Для всех зависимостей используем моки

Ingredient ingredient = Mockito.mock(Ingredient.class);
Burger burger = new Burger();
burger.addIngredient(ingredient);
assertEquals(1, burger.ingredients.size());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Для юнит-тестов придерживаемся подхода: один тест, значит одна проверка. Если очень хочется несколько проверок -- тогда используем softAssertions. Поправь, пожалуйста, во всем коде


@Test
public void testRemoveIngredient_RemovesIngredient() {
Ingredient ingredient1 = Mockito.mock(Ingredient.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. При нейминге не рекомендуется использовать числа (Field2), их еще называют magicNumbers. Очень тяжело поддерживать код с magicNumbers.

burger.setBuns(bun);
burger.addIngredient(ingredient1);
burger.addIngredient(ingredient2);
assertEquals(325.0f, burger.getPrice(), 0.001);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛔️Нужно исправить. Для юнит-тестов применим подход: один тест, значит одна проверка. В этом тесте две проверки (Mockito.verify, assertEquals), а должна быть одна. Исправь, пожалуйста, этот момент во всем коде.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants