마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

InstrumentationTestCase에서 UiAutomation가 자꾸 Null이 뜹니다 ㅠㅠ

0 추천

안녕하세요!

제가 UiAutomation.injectInputEvent(motionUp, true);를 사용해서 매크로를 만들어 보려고 합니다.

 

https://youtu.be/_SlBHUW0ybM 의 설명을 보아하니

UiAutomation is a new low level testing API which was introduced with Android 4.3. UiAutomation allows instrumentation tests to test across application boundaries. It supports full screen introspection support, taking screenshots, changing device orientation and injection of raw input events.

raw input events가 가능한 저레벨 테스트 API 라고  하네요..

그래서 구글링을 바탕으로 아래와 같은 시도를 해보았습니다

public class TestInstrumentation extends InstrumentationTestCase {
	
	private Instrumentation i;
	private UiAutomation automation;
	final long eventTime = SystemClock.uptimeMillis();
	private int inputDevice = InputDevice.SOURCE_TOUCHSCREEN;
	
	@Override
	public void setUp() throws Exception {
		super.setUp();
		i = getInstrumentation();
		automation = i.getUiAutomation();//오류 발생!!
    }
	
    public void uiautomationTouch(int x, int y){
    	
	    MotionEvent motionDown = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_DOWN,
	            x,  y, 0);
	    motionDown.setSource(inputDevice);
	    automation.injectInputEvent(motionDown, true);
	    MotionEvent motionUp = MotionEvent.obtain(eventTime, eventTime, KeyEvent.ACTION_UP,
	            x, y, 0);
	    motionUp.setSource(inputDevice);
	    automation.injectInputEvent(motionUp, true);
	    
	    motionUp.recycle();
	    motionDown.recycle();
	}
}

 

위에서 getUiAutomation()만 나오면 계속 NullPointerException 에러가 뜨더라구요 ㅠㅠㅠ

 

여기서 질문!!!!

 

 

1. 테스트용 API는 컴퓨터로 리눅스 커널이나 cmd 같은거에 뭘 입력해야 하는데, 제가 입력을 안해서 에러가 나는건가요?

 

2. 위의 nullPointerException에러는 어떻게 고칠 수 있을까요??

 

답변 달아주시면 정말 감사드리겠습니다!!!

레비튼 (320 포인트) 님이 2015년 6월 7일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...