@RunWith

- Parent 에 정의해두면 Child 에도 적용됨

- Android 의 경우 기본으로 정의하지 않으면 gradle 에 정의된 AndroidJunitRunner 가 기본으로 설정됨

 

@PrepareForTest

- 우선순위 : Method > Child Class > Parent Class

- add 가 아니라 overwrite 됨

- byte code 로 조작해야하는 클래스

  (final, native, static, private 메소드)

 

 

@Test

별로 각자의 테스트 클래스 인스턴스가 생성됨

 

src/main/java/aaa/Hello.class

src/test/java/bbb/Hello.class (같은 pkg - Seperate But Equals)

 

JUnit 4 - org.junit.Assert

Junit5 - junit.framework.Assert

 

RectF, PointF 와 같은 Android 클래스들은 JVM 에서 동작하지 않음

- 동일 경로에 해당 클래스를 구현

- powermock 을 활용해 동일하게 동작하도록 코드 구현 (2)

- Robolectric 과 함께 사용하는 경우, @PowerMockIgnore 잘 설정해줘야됨

 

(2)

whenNew(PointF.class).withanyarguments(anyFloat(),anyfloat()). thenAnswer(new Answer() {

      answer() {

Object[] args = invocation.getArguments();

PointF mockPointF = mock(PointF.class);

if (args[0] instance of Float) {
  mockPointF.x = (float)args[0];

}

if (args[1] instance of Float) {
  mockPointF.y = (float)args[1];

}

return mockPoint;

 

 

 

 

PowerMock 은 나머지 3개의 Runner 보다 속도가 많이 느림

 

SingleTon Class test

1. 수행하고, @After 에서 null 처리하여 초기화

2. @Before 에서 Constructor(A class) constructor = A class.class.getDeclaredConstructor();

    constuctor.setAccessible(True);

    a = constructor.newInstance();

   새 인스턴스로 테스트

3. 기본적인 코드가 잘 동작하도록 환경설정

4. PowerMock mockStatic() 사용

 

 

 

 

+ Recent posts