1import org.junit.Assert;
2import org.junit.Test;
3
4public class Test {
5
6 public static int square(int n) {
7 return n * n;
8 }
9
10 @Test
11 public void squareTest() {
12 Assert.assertEquals(25, square(5));
13 Assert.assertEquals(16, square(4));
14 Assert.assertEquals(9, square(3));
15 Assert.assertEquals(4, square(2));
16 Assert.assertEquals(1, square(1));
17 }
18}
19
1-It is an open-source testing framework for java programmers.
2-Test runner support to execute the test case
3-It is one of the unit testing framework.
4-Assertion support for checking the expected result.
5-Annotation support for test cases
6
1import org.junit.Assert;
2import org.junit.Test;
3
4public class Test {
5
6 public static int square(int n) {
7 return n * n;
8 }
9
10 @Test
11 public void squareTest() {
12 Assert.assertEquals(25, square(5));
13 Assert.assertEquals(16, square(4));
14 Assert.assertEquals(9, square(3));
15 Assert.assertEquals(4, square(2));
16 Assert.assertEquals(1, square(1));
17 }
18}
1import static org.junit.jupiter.api.Assertions.assertEquals;
2
3import org.junit.jupiter.api.Test;
4
5public class MyTests {
6
7 @Test
8 public void multiplicationOfZeroIntegersShouldReturnZero() {
9 MyClass tester = new MyClass(); // MyClass is tested
10
11 // assert statements
12 assertEquals(0, tester.multiply(10, 0), "10 x 0 must be 0");
13 assertEquals(0, tester.multiply(0, 10), "0 x 10 must be 0");
14 assertEquals(0, tester.multiply(0, 0), "0 x 0 must be 0");
15 }
16}
1-It is an open-source testing framework for java programmers.
2-Test runner support to execute the test case
3-It is one of the unit testing framework.
4-Assertion support for checking the expected result.
5-Annotation support for test cases