문제

I've been trying to unit test a simple calculator app with ActivityUnitTestCase. The code for my calculator app

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_page);

    disp = (TextView) findViewById(R.id.disp);

    n1 = (EditText) findViewById(R.id.n1);
    n2 = (EditText) findViewById(R.id.n2);

    calc = (Button) findViewById(R.id.calc);


    calc.setOnClickListener(this);

}
public void onClick(View v) {
    double num1 = Double.valueOf(n1.getText().toString());
    double num2 = Double.valueOf(n2.getText().toString());

    Intent in = new Intent(this,CalcActivity.class);
    in.putExtra("num1",num1);
    in.putExtra("num2", num2);
    startActivity(in);
}

I want to be able to perform some operations on the two numbers and then send it through the intent. My question is, how do you examine the contents of the outgoing intent during the unit test ?

도움이 되었습니까?

해결책

Found it. There's a function in ActivityUnitTestCase that does the trick.

Intent in = getStartedActivityIntent();

which will return the launch intent if your Activity under test calls startActivity(Intent) or startActivityForResult(Intent, int).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top