Basic Unit Testing with JUnit Testing Framework - Java Testing

Posted by Coding Yoda on November 24th, 2018

I decided to make a quick video and run through creating a simple test with JUnit. In the video I create an basic acceptance test for a method.

I may turn this into a series of videos showing the different things that JUnit can do and the advantages of tests and TDD(Test-driven development).

In this example I have created a test for a Calculator class that has an Add method. The Add method takes in two integers and sums them together.

Setting up a test in JUnit is very easy. Tests increase the quality of code based and give you confidence in your code. In this example I set up an assertEquals check to see if I get the expected results. If they match the test will return true and pass, if not it will return false, fail and show you the expected result.


Screenshots of the code and the JUnit Test


Calculator Class for Testing
JUnit Test for Calculator Add Method

Thanks for reading/watching and I hope this helps.