2011-09-06 2 views

답변

2

테스트중인 우리의 응용 프로그램, 시대의 여러 수를 실행하는 방법이 있나요 그것은 당신이 해결책을 찾을 당신 계측 클래스

public void testFirstTime() { 
    Intent intent = new Intent(getInstrumentation().getTargetContext(), MyActivity.class); 
    Foo foo = new Foo(); 
    intent.putExtra("param", foo); 
    setActivityIntent(intent); 
    MyActivity myActivity = getActivity(); 
    assertNotNull(myActivity); 
    // do some assert 
} 

public void testSecondTime() { 
    Intent intent = new Intent(getInstrumentation().getTargetContext(), MyActivity.class); 
    Bar bar = new Bar(); 
    intent.putExtra("param", bar); 
    setActivityIntent(intent); 
    MyActivity myActivity = getActivity(); 
    assertNotNull(myActivity); 
    // do some other assert 
} 
0

에있어 얼마나 많은 시험 방법에 의존하지 않습니다 가장 아름다운 것.

protected void setUp() throws Exception { 

    setActivityInitialTouchMode(false); 



    if(stage == 0){ 
     in1 = new Intent(); 
     in1.putExtra(Defintiens.EXTRA_1, CopyUSerDetailsServiceMock.getMock1()); 
     in1.putExtra(Defintiens.EXTRA_2, UserProtfolioMock.getMock1()); 
     setActivityIntent(in1); 
    }else if (stage == 1){ 
     in2 = new Intent(); 
     in2.putExtra(Defintiens.EXTRA_1, getMock1()); 
     in2.putExtra(Defintiens.EXTRA_2, getMock1()); 
     setActivityIntent(in2); 
    }else if (stage == 3){ 
     in3 = new Intent(); 
     in3.putExtra(Defintiens.EXTRA_1, getMock1()); 
     in3.putExtra(Defintiens.EXTRA_2, getMock1()); 
     setActivityIntent(in3); 
    }else if (stage == 4){ 
     in4 = new Intent(); 
     in4.putExtra(Defintiens.EXTRA_1, getMock1()); 
     in4.putExtra(Defintiens.EXTRA_2, getMock1()); 

    } 

    mActivity = getActivity(); 


    super.setUp(); 
} 


    @Override 
    protected void tearDown() throws Exception { 
     mActivity.finish(); 
     super.tearDown(); 
    } 

    private static int stage = 0; 
    public void testInjectExtra2(){ 
     stage = 2; 
     //In each test you should set the stage to tour testing 
     //...... Run your test 
} 

지금 활동이 목적 추가와 함께 다시 시작됩니다 각 테스트에서 내가

를 원하는 : 내가했던 설정에서
관련 문제