Do unit test with Junit in intellij
package Service;
//Main
public class JunitFun {
int add(int i, int j) {
return i + j;
}
int subtract(int i, int j) {
return i - j;
}
}
package Service;
import org.junit.Test;
import static org.junit.Assert.*;
public class JunitFunTest {
JunitFun cal = new JunitFun();
@Test
public void add() {
int result =cal.add(1 ,3 );
assertEquals(4, result);
}
}
//Test
package Service;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class JunitFunTest {
JunitFun cal;
@Before
public void setup(){
cal = new JunitFun();
System.out.println("setup!");
}
@Test
public void divide() {
assertEquals(3, cal.divide(3,1));
System.out.println("divide!");
}
@Test
public void trueFalse() {
assertTrue(true);
System.out.println("boolean!");
}
@After
public void teardown() {
System.out.println("teardown!");
}
}
So the instance is form the main class. it's just basic calculation.
I used assert library of java. And some say assertj is better than java. So nexttime I would try.
'Footstep . 발자취' 카테고리의 다른 글
2020-03-05-My footstep today goals (0) | 2020.03.20 |
---|---|
2020-03-04-Today Eng words (0) | 2020.03.20 |
2020-03-03-My footstep today goals (0) | 2020.03.19 |
2020-03-02-My footstep today goals (0) | 2020.03.19 |
2020-03-01-My footstep today goals (0) | 2020.03.19 |