Skip to content

Commit

Permalink
Update to Srping Boot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
in28minutes committed Oct 3, 2022
1 parent 2578f5f commit 52c62e6
Show file tree
Hide file tree
Showing 54 changed files with 1,668 additions and 1,775 deletions.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
## First 5 Steps in JUnit

- Git Repository - https://github.com/in28minutes/getting-started-in-5-steps
- Pre-requisites - Java & Eclipse - https://www.youtube.com/playlist?list=PLBBog2r6uMCSmMVTW_QmDLyASBvovyAO3
- We will use embedded maven in Eclipse

### Step 1 : What is JUnit and Unit Testing?
- What is JUnit?
- What is Unit Testing?
Expand All @@ -26,6 +22,11 @@
- @Before @After annotations
- @BeforeClass @AfterClass annotations


<!---
Current Directory : /Users/rangakaranam/Ranga/git/00.courses/spring-boot-master-class/03.JUnit-Introduction-In-5-Steps-V2
-->

## Complete Code Example


Expand All @@ -35,90 +36,137 @@
package com.in28minutes.junit;

public class MyMath {
int sum(int[] numbers) {

//{1,2,3} => 1+2+3 = 6
public int calculateSum(int[] numbers) {

int sum = 0;
for (int i : numbers) {
sum += i;

for(int number:numbers) {
sum += number;
}

return sum;
}


}
```
---

### /test/com/in28minutes/junit/AssertTest.java
### /test/com/in28minutes/junit/MyAssertTest.java

```java
package com.in28minutes.junit;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class AssertTest {
class MyAssertTest {

List<String> todos = Arrays.asList("AWS", "Azure", "DevOps");

@Test
public void test() {
boolean condn = true;
assertEquals(true, condn);
assertTrue(condn);
// assertFalse(condn);
void testAsserts() {
boolean test = todos.contains("AWS");//Result
boolean test2 = todos.contains("GCP");//Result

//assertEquals(true, test);
assertTrue(test);
assertFalse(test2);
//assertNull,assertNotNull
assertArrayEquals(new int[] {1,2}, new int[] {2, 1});

assertEquals(3, todos.size());
}

}
```
---

### /test/com/in28minutes/junit/MyMathTest.java
### /test/com/in28minutes/junit/MyBeforeAfterTest.java

```java
package com.in28minutes.junit;

import static org.junit.Assert.assertEquals;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
class MyBeforeAfterTest {

public class MyMathTest {
MyMath myMath = new MyMath();

@BeforeAll
static void beforeAll() {
System.out.println("beforeAll");
}

@BeforeEach
void beforeEach() {
System.out.println("BeforeEach");
}

@Before
public void before() {
System.out.println("Before");
@Test
void test1() {
System.out.println("test1");
}

@After
public void after() {
System.out.println("After");
@Test
void test2() {
System.out.println("test2");
}

@Test
void test3() {
System.out.println("test3");
}

@BeforeClass
public static void beforeClass() {
System.out.println("Before Class");
@AfterEach
void afterEach() {
System.out.println("AfterEach");
}

@AfterClass
public static void afterClass() {
System.out.println("After Class");
@AfterAll
static void afterAll() {
System.out.println("afterAll");
}

// MyMath.sum
// 1,2,3 => 6
}
```
---

### /test/com/in28minutes/junit/MyMathTest.java

```java
package com.in28minutes.junit;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class MyMathTest {

private MyMath math = new MyMath();

@Test
public void sum_with3numbers() {
System.out.println("Test1");
assertEquals(6, myMath.sum(new int[] { 1, 2, 3 }));
void calculateSum_ThreeMemberArray() {
assertEquals(6, math.calculateSum(new int[] {1,2,3}));
}

@Test
public void sum_with1number() {
System.out.println("Test2");
assertEquals(3, myMath.sum(new int[] { 3 }));
void calculateSum_ZeroLengthArray() {
assertEquals(0, math.calculateSum(new int[] {}));
}

}
```
---
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.in28minutes.junit;

public class MyMath {
int sum(int[] numbers) {

//{1,2,3} => 1+2+3 = 6
public int calculateSum(int[] numbers) {

int sum = 0;
for (int i : numbers) {
sum += i;

for(int number:numbers) {
sum += number;
}

return sum;
}


}
Loading

0 comments on commit 52c62e6

Please sign in to comment.