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
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}
1import junit.framework.*;
2
3public class JavaTest extends TestCase {
4 protected int value1, value2;
5
6 // assigning the values
7 protected void setUp(){
8 value1 = 3;
9 value2 = 3;
10 }
11
12 // test method to add two values
13 public void testAdd(){
14 double result = value1 + value2;
15 assertTrue(result == 6);
16 }
17}