Hello everyone,
Today I want share a video for JUnit beginners like us.
“Java Unit Testing with JUnit – Tutorial – How to Create And Use Unit Tests”
By Coding with John
Here is the link: https://www.youtube.com/watch?v=vZm0lHciFsQ
I highly recommend everyone to watch this video before doing Homework 1. Because the function we want to implement on Homework1 is almost logically very similar to what he described. The blogger introduces the working principle of JUnit almost from scratch, and shows step by step how to create a Test Method and its working logic.
For example, From 3 to 10 minutes into the video, he introduces the structure of the Test method, including the use of calculation methods and assert statements.
@Test
void twoPlusTwoShouldEqualFour(){
var calculator = new SimpleCalculator();
assertEquals(expected:4, calculator. add(numberA: 2, unmberB: 2)
}
The above code shows us that if unmberA plus numberB equals 4, then we can pass the test. If it is not 4, it will fail to pass. It also shows us the various functions of assert statement. Such as assertEquals, assertNotEquals, assertTrue, assertFalse, assertNull and so on. We gonna use all of them in every scenario.
Next, the video talks about a more complicated testing method. When there are multiple results, we need to test every scenario that may occur. And he talks about some loopholes in the testing logic. For example, in 15 minutes, he gives an example The condition of return C was changed from 80 to 81, and it still passed the test, even though 80 should return B. This does not mean that our test scenario is bad, but we may need more code to describe the test conditions.
However, I recommend this video because it is really suitable for beginners. When I watched this video, many questions were solved. Although these are very basic things, everything you need to learn later is based on these foundations. I believe that learning the knowledge taught in the video will be very beneficial to our future study. I will follow this blogger. The knowledge he talks about is very easy to absorb and understand.
From the blog CS@Worcester – Ty-Blog by Tianyuan Wang and used with permission of the author. All other rights reserved by the author.