Java Programming Language: JUnit Unit Test Tutorial

Creating a Function to Unit Test

public class MyUnitTestExample {
public static int onePlusTwo() {
return 3;
}
}

Writing a Unit Test for our Function

import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class MyUnitTestExampleTest {
@Test
void test() {
assertEquals(3, MyUnitTestExample.onePlusTwo());
}
}
@Test
void test() {
assertEquals(4, MyUnitTestExample.onePlusTwo());
}

Testing a Function with Parameters

public static int add(int numberA, int numberB) {
return numberA + numberB;
}
@Test
void test2() {
assertEquals(3, MyUnitTestExample.add(1, 2));
}

Conclusion

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

.Properties or .ini to yaml

Best Practices for Developing a Mobile App

Memory management on iOS

5 Simple Ways to Create a Powerful Spiritual Routine

Is it Agile, Scrum, DevOps or is it SAFe?

YARN Job History logs issues

Kyiv Legal Tech Hackathon — Epilogue

If an Event is Published to a Topic and No One is Around to Consume it, Does it Make a Sound?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jesse L

Jesse L

More from Medium

Java Programming Language Tutorial: Intro to ArrayLists

Working with Java Variables

Title image

Object Oriented Programming with Java

Java: First Repeated Character in a String