Junit4
[ Junit4 ] assertNotSame, assertSame : 두 변수의 참조 값이 같은지 여부
kwanghyup
2020. 6. 17. 23:59
public class Person {
private String name;
private int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
import org.junit.Test;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
public class SampleTest {
@Test
public void test_assertNotSame(){
// 두 변수가 다른 객체를 참조하는 경우 테스트에 성공한다.
Person person1 = new Person("lee",36);
Person person2 = new Person("lee",36);
assertNotSame(person1,person2);
}
@Test
public void test_assertSame(){
// 두 변수가 같은 객체를 참조하는 경우 테스트에 성공한다.
Person person1 = new Person("lee",36);
Person person2 = person1;
assertSame(person1,person2);
}
}