🏠 | 💻 IT | Java |

JUnit

Простейший тест

Создадим файл Main.java со следующим содержанием

package ru.andreyolegovich.it.junit; public class Main { public static void main(String[] args) { } static int addFunc(int var_1, int var_2){ int sum = var_1 + var_2; return sum; } }

Теперь нужно создать файл с тестом и подключить JUnit

В IntelliJ достаточно сделать правый клик на main → Go To → Test → Create New Test → Выбрать JUnit 5 → Fix

Код нужен примерно такой

package com.pluralsight.organized; import org.junit.jupiter.api.Test; import static com.pluralsight.organized.Main.addFunc; import static org.junit.jupiter.api.Assertions.*; class MainTest { @Test public void addCorrectly() { assertEquals(4,addFunc(1,3)); } }

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: