2011-09-06 53 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 
} 

現在,在每個測試活動將與意圖額外的重新啓動,我想

相關問題