2017-10-26 19 views
0

계측 테스트 실행 중 시스템과 통신하는 방법이 있는지 알고 싶습니다. 예 : 온보드 IR 포트가있는 전화기 & 개인 SDK를 통해 작업 할 수 있으며 응용 프로그램과 함께 조정할 수도 있습니다. Instrumentation 테스트 케이스에서는 별도의 테스트를 실행하기 전에 구성하려는 외부 이벤트를 기반으로 테스트 응용 프로그램 동작을 원합니다. 그것은 매우 간단한 예입니다하지만 "조건"이 많이있다, 고에 SDK 업데이트 주파수 AndroidJUnit을 통한 프로세스 간 또는 adb 통신

@Test 
public void test() throws Exception { 
    setupExternalCondition(condition1_ON); // setup external transiver 
    assertNotNull(IR.read()); 
    assertTrue(assertIR.write()); 

    setupExternalCondition(condition1_OFF); 
    assertNotNull(IR.read()); 
    assertFalse(IR.write()); 
} 

처럼입니다
보인다. 이 모든 확인 작업을 수동으로 수행 할 수는 없으며 "transiver & SDK 팀"에게 보험 적용을위한 단원 테스트 작성을위한 모의 상태 목록 작성을 요청할 수 없습니다. 그래서 어떻게 든 외부 조건을 설정하기 위해 로컬 컴퓨터 (또는 CI 컴퓨터)에서 이벤트 (또는 테스트 사례 실행 전에 testName)를 수신하기 위해 TestRuner에 외부 구성 요소 실행을 주입하려고합니다.

appUnderTest에서 TCP 서버를 실행하고 외부 조건 변경을 요청하는 간단한 해결책 - 안정적 연결 (wifi)에 대해 확실하지 않으므로 adb를 통해 수행 할 수 있습니다. .

제안 사항?

P.S : 테스트 장치에 루트 권한이 있습니다.

답변

0

그래서 나쁘지는 않지만 이상적인 해결책을 찾으십시오. 여전히 더 나은 제안을 기다리는 것이 아니라면이 대답이 다른 사람에게 도움이 될 수 있습니다. 로컬 컴퓨터와 AndroidJUnitTest 사이에 "다리를 건설"에 대한 나는 시험 옆에 클래스를 추가 :

class IPCServiceBridge extends BroadcastReceiver { 
    private static final String FILTER_ID = "IPC_SERVICE"; 
    private static IPCServiceBridge sInstance; 
    private boolean mIsPermitted; 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     if (intent.getAction().equals("ipc.service.action")) { 
      mIsPermitted = true; 
     } 
    } 


    public static IPCServiceBridge getInstance() { 
     if (sInstance == null) { 
      sInstance = new IPCServiceBridge(); 
      IntentFilter filter = new IntentFilter(); 
      filter.addAction("ipc.service.action"); 
      Context context = InstrumentationRegistry.getContext(); 
      context.registerReceiver(sInstance, filter); 
     } 
     return sInstance; 
    } 

    public void sendIpcCommand(String commandName) { 
     try { 
      int i = 30; 
      mIsPermitted = false; 
      while (i > 0) { 
       pub("request:" + commandName); 
       Thread.sleep(1000); 
       if (mIsPermitted) { 
        break; 
       } 
       i--; 
      } 
     } catch (InterruptedException e) { 
      throw new RuntimeException(e); 
     } 
     if (!mIsPermitted) { 
      throw new RuntimeException("IPC service does not respond"); 
     } 
    } 

    private static void pub(String msg) { 
     Log.e(FILTER_ID, msg); 
    } 
} 

내가 ADB 로그 캣 -s "FILTER_NAME", 구문 분석하고 InsttUnit 시험에 적용해야하는 조건 확인을 시작보다. 조건이 준비되면 필요한 조치로 방송 수신기를 되돌려 보냅니다.

@Test 
public void test2() throws Exception { 
    IPCServiceBridge.getInstance().sendIpcCommand("CONDITION#123"); 
} 

잘 작동하지만 매우 안정적 일지는 확실하지 않습니다.